如何使用 UIKeyboardWillShowNotification
我想创建一个与 iPhone 的短信应用程序(消息)完全相同的 ChatView。我正在以编程方式执行此操作,并尝试使用键盘向上移动 textView 。我想在 UIKeyboardWillShowNotification 调用的函数中执行此操作。你能帮我调试这个错误吗?
在 ChatViewController.m 中,我在 loadView 函数中为 UIKeyboardWillShowNotification 设置了一个侦听器,并将 self 设置为 textView 委托,但它崩溃了,并显示: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“*** -[ChatViewController KeyboardWillShow]:无法识别的选择器发送到实例
但我在 ChatViewController.m 中定义了 KeyboardWillShow 为什么找不到该功能?
以下是重要文件:
http://github。 com/acani/acani-chat/blob/master/Lovers/Classes/ChatViewController.h http://github.com/acani/acani- chat/blob/master/Lovers/Classes/ChatViewController.m
我注释掉了监听器,这样它就不会崩溃。
请随意 git clone [email protected]:acani/acani-chat。谢谢
!
I want to create a ChatView exactly like iPhone's texting app (Messages). I'm doing it programmatically and am trying to move the textView up with the keyboard. I want to do this in a function that gets called by UIKeyboardWillShowNotification. Could you help me debug this error?
In ChatViewController.m, I set a listener for UIKeyboardWillShowNotification in the loadView function, and I set self as the textView delegate, but it crashes, saying:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[ChatViewController keyboardWillShow]: unrecognized selector sent to instance
But I define keyboardWillShow in ChatViewController.m
Why isn't it finding that function?
Here are the important files:
http://github.com/acani/acani-chat/blob/master/Lovers/Classes/ChatViewController.h
http://github.com/acani/acani-chat/blob/master/Lovers/Classes/ChatViewController.m
I commented out the listeners so that it doesn't crash.
Feel free to git clone [email protected]:acani/acani-chat.git
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您已注释掉的第 120 行和第 121 行,但我认为这不是本意,因为没有其他引用订阅通知,当您传递选择器时会出现问题。 Objective-C 消息名称中的冒号 (:) 是名称本身的一部分。因此,您传入的选择器缺少一个尾随冒号。修复该问题,这将消除您的错误。
另外,当视图消失时 (viewDidUnload),您应该考虑调用
removeObserver:
。Lines 120 and 121 which you have commented out, but I presume are not meant to be since there is no other references to subscribing for notifications, has a problem when you pass the selector. The colon (:) in Objective-C message names are part of the name themselves. Therefore, you are missing a trailing colon to the selector you're passing in. Fix that, and that will get rid of your error.
Also, you should look at making a call to
removeObserver:
when your view goes away (viewDidUnload).