OStack程序员社区-中国程序员成长平台

标题: iphone - "unrecognized selector sent to instance"出现键盘时 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 17:40
标题: iphone - "unrecognized selector sent to instance"出现键盘时

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


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

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






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4