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

发布于 2024-12-06 08:39:23 字数 992 浏览 6 评论 0原文

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

}

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

When I click a text field into my app screen and the keyboard is showing up xcode debugger shows this error:

[mainViewController keyboardWasShown]: unrecognized selector sent to instance 0x5867ac0

In the viewDidLoad method of the mainViewController I'm calling the registerForKeyboardNotifications method like that:

[self registerForKeyboardNotifications];

Here's its implementation (in 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
{

}

Any idea what could be wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

醉殇 2024-12-13 08:39:23

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

Make sure the notification selector has the colon at the end; this is important, keyboardWasShown and keyboardWasShown: are different selectors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文