iphone - "unrecognized selector sent to instance"当键盘出现时

标签 iphone ios ios4 nsnotificationcenter nsnotification

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

}

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

最佳答案

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

关于iphone - "unrecognized selector sent to instance"当键盘出现时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7542827/

相关文章:

ios - 是否有必要将Mac OS X的beta版本用作iOS beta版本的开发环境?

iphone - uitableview reloadRowsAtIndexPaths 不工作

ios - 如何检测 UIButton 的触摸结束事件?

ios - iPhone降噪功能,我可以禁用\调音吗?

iphone - 错误 : "-[NSCFString sizeWithTextStyle:]: unrecognized selector" in IPhone SDK

iphone - 如何创建像 iPhone 消息应用程序中那样的输入文本 Controller

iphone - 如何使用核心数据获取按距离排序的地点列表

iphone - 如何创建一个从下到上包含0到1不透明度值(alpha值)的UIView?

ios - 为单个区域设置与其他区域不同的 IAP 定价

iPhone 应用内短信 MFMessageComposeViewController 自动发送