当我单击应用程序屏幕中的文本字段并且键盘显示时,xcode 调试器显示此错误:
[mainViewController keyboardWasShown]: unrecognized selector sent to instance 0x5867ac0
在 mainViewController 的 viewDidLoad 方法中,我像这样调用 registerForKeyboardNotifications 方法:
[ self 注册键盘通知];
这是它的实现(在 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
{
}
知道可能出了什么问题吗?
最佳答案
确保通知选择器末尾有冒号;这很重要,keyboardWasShown
和 keyboardWasShown:
是不同的选择器。
关于iphone - "unrecognized selector sent to instance"当键盘出现时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7542827/