2

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

}

知道有什么问题吗?

4

1 回答 1

4

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

于 2011-09-25T23:19:13.433 回答