“无法识别的选择器发送到实例”当键盘出现时
当我单击应用程序屏幕中的文本字段并且键盘显示时,xcode 调试器显示此错误:
[mainViewController keyboardWasShown]: unrecognized selector sent to instance 0x5867ac0
在 mainViewController 的 viewDidLoad 方法中,我调用如下所示的 registerForKeyboardNotifications 方法:
[self registerForKeyboardNotifications];
这是它的实现(在 mainViewController.m 中):
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
}
知道可能出了什么问题吗?
When I click a text field into my app screen and the keyboard is showing up xcode debugger shows this error:
[mainViewController keyboardWasShown]: unrecognized selector sent to instance 0x5867ac0
In the viewDidLoad method of the mainViewController I'm calling the registerForKeyboardNotifications method like that:
[self registerForKeyboardNotifications];
Here's its implementation (in mainViewController.m):
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
}
Any idea what could be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
确保通知选择器末尾有冒号;这很重要,
keyboardWasShown
和keyboardWasShown:
是不同的选择器。Make sure the notification selector has the colon at the end; this is important,
keyboardWasShown
andkeyboardWasShown:
are different selectors.