当我单击文本字段到我的应用程序屏幕并且键盘显示时,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
{
}
知道可能出现什么问题吗?
答案 0 :(得分:4)
确保通知选择器的末尾有冒号;这很重要,keyboardWasShown
和keyboardWasShown:
是不同的选择器。