- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个带有自定义 View 的 xib 文件,上面有很多文本字段 subview 。我已经将每个文本字段的委托(delegate)设置为文件所有者,并且能够成功地使用 texfield 委托(delegate)方法。但不幸的是,键盘通知方法 keyboardWillShow: 和 keyboardWillHide: 根本没有被调用。
我在 textfieldShouldBeginEditing 添加了观察者,并在 textFieldDidEndEditing 移除了观察者。
这是我的代码片段:
添加观察者
-(void) textFieldShouldBeginEditing : (UITextField *) textField{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
移除观察者
-(void) textFieldDidEndEditing : (UITextField *) textField{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
//通知的方法
- (void)keyboardWillShow:(NSNotification *)notification
{
NSLog(@"Here");
}
- (void)keyboardWillHide:(NSNotification *)notification
{
NSLog(@"There");
}
//keyboardwillShow 和 keyboardWillHide 中的任何一个都不会被调用。
如果有人可以帮助我找出我的代码问题或我可能遗漏的任何底层问题,那就太好了。
最佳答案
当您通过编辑 textView 显示键盘时,您正在添加一个观察者。它不会调用,因为键盘已经显示。您应该在 viewWillAppear
上添加观察者并移除 viewWillDisappear
方法。
关于ios - 不调用 NSNotification keyBoardWillShow 和 keyboardWillHide,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42029826/
我正在为我的 iPhone 应用开发一个类,我希望它能够注册并了解应用状态的变化(UIApplicationDidEnterBackgroundNotification 等)。有没有一种方法可以注册通
这是我得到的错误 Thread 1:EXC_BAD_ACCESS (code=2, address=0xb7ffffc) 在这条线上 [[NSNotificationCenter defaultCen
你能解释一下什么是NSNotification 的目的,以及我可以在哪些情况下使用是吗? 通知是否调用所有类在应用程序中,或者它是否调用特定的类,通过传递代表? 是否可以创建1通知,并在多个类(cla
我正在开发一个电子书阅读器,我遇到了以下问题。我正在使用 IBAction 方法来发布 NSNotification,一旦点击按钮,它就会调用操作方法。它第一次工作得非常好...每次我点击按钮时都必须
谁能解释一下 NSNotificationCenter 的重要性吗? 在哪里使用它们? NSNotificationCenter 与 AppDelegate 有什么区别? 最佳答案 Apple 在 C
在我的 NSApp 委托(delegate)中,我添加了一个对象的观察者,该对象是 NSWindow 子类,该对象在委托(delegate)本身中启动,并在单击窗口后发布通知。选择器也在委托(dele
我正在尝试在我的多线程应用程序中获取通知 NSTaskDidTerminateNotification,但无法使其正常工作。当我在单线程应用程序上测试它时,它似乎确实有效。在 init 中,我有 [[
在单线程中使用 NSNotifications 时是否存在竞争条件问题?这是一个示例方法: - (void) playerToggled: (NSNotification *) notificatio
WebKit 的 WebHistory API 按日期分隔其项目。因此,当日期发生变化时,我需要重新分配任何“昨天”和/或“(早些时候)今天”(或“明天”!)标签。有 NSNotification 吗
我计划编写一个小守护程序来检测另一个应用程序是否崩溃,一直认为系统会发送 NSWorkspaceDidTerminateApplicationNotification,但事实并非如此。 假设我不想创建
我正在阅读 iOS Big Nerd Ranch 书,其中一个示例显示了如何将观察者添加到 NSNotificaionCenter : [[NSNotificationCenter defau
我想要一种方法,可以暂停执行,直到收到通知后再继续。收到通知后它将继续执行。执行此操作的最佳方法是什么? 最佳答案 你可以使用 NSRunLoop - (BOOL)method { __block B
在我的游戏中,我正在发送 NSNotification 以在游戏过程中隐藏横幅广告,并在主菜单和游戏结束场景上显示横幅广告。这工作正常,除了由于某种原因每次我点击屏幕时都会调用隐藏广告的通知并且广告消
我的 didFinishLaunchingWithOptions 中有以下代码 NotificationCenter.default.addObserver( self,
什么相当于 Android 中的 NSNotification? 我需要能够发送和接收来自任意类(不一定是 Activity )的通知。 最佳答案 这种模式称为 EventBus,并且有一些用于此的库
我正在做一个关于 NSNotification 的简单教程,但在正确执行它时遇到了一些问题。当我单击第一个 View 上的按钮时,第二个 View 中的文本字段没有得到更新。当我通过在 receive
我有一个多线程程序通过 NSNotificationCenter 发送消息(addObserver:.. 和 postNotification:... 方法)。 线程订阅不同的通知,其中一些是共享的,
我在旋转设备时收到多个 UIKeyboardDidShowNotification 和 UIKeyboardDidHideNotification 通知,我不明白为什么。 我有一个应用程序,可以让您为
我经常在 viewDidLoad 中注册 NSNotification 并在 dealloc 中取消注册。我们在 ios 5 中没有 dealloc。我在哪里注销 NSNotification? 最佳
有没有办法在不延迟任何当前完成的代码的情况下触发 NSNotification(可能会触发大量工作)? 具体来说,我有一个 UIPanGestureRecognizer,它允许用户平移几个月、一月、二
我是一名优秀的程序员,十分优秀!