键盘出现时“无法识别的选择器发送到实例”

时间:2011-09-25 00:26:49

标签: iphone ios ios4 nsnotificationcenter nsnotification

当我单击文本字段到我的应用程序屏幕并且键盘显示时,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
{

}

知道可能出现什么问题吗?

1 个答案:

答案 0 :(得分:4)

确保通知选择器的末尾有冒号;这很重要,keyboardWasShownkeyboardWasShown:是不同的选择器。