当我在我的应用程序屏幕中单击文本字段并且键盘显示时,xcode 调试器显示此错误:
[mainViewController keyboardWasShown]: unrecognized selector sent to instance 0x5867ac0
在 mainViewController 的 viewDidLoad 方法中,我像这样调用 registerForKeyboardNotifications 方法:
[self registerForKeyboardNotifications];
这是它的实现(在 mainViewController.m 中):
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selectorselector(keyboardWasShown name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selectorselector(keyboardWillBeHidden name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShownNSNotification*)aNotification
{
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHiddenNSNotification*)aNotification
{
}
知道可能出了什么问题吗?
Best Answer-推荐答案 strong>
确保通知选择器末尾有冒号;这很重要,keyboardWasShown 和 keyboardWasShown: 是不同的选择器。
关于iphone - "unrecognized selector sent to instance"出现键盘时,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/7542827/
|