iOS - NSNotificationCenter 多个UIKeyboard通知
我有两个视图控制器,我们称它们为 A 和 B
(1) 在 AI 中显示包含文本字段的 popOver
(2)B中有一个UITextView用于简单的文本编辑
我必须管理A和B中的键盘来滚动键盘隐藏的内容。我知道如何重新定位内容。我需要的是一种对相同通知类型具有不同行为的方法,在我的 UIKeyboardWill(Show/Hide)Notification 中。
到目前为止我所做的:
(1) 我已在每个控制器中添加了此代码
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidAppear:)
name:UIKeyboardWillShowNotification
object:self.view.window
as I said I've added this code to A and B, but doesn't work as I expected. For instance When I click inside the textView two methods are triggered the keyboardDidAppear of A and the keyboardDidAppear of B, the same happens with the UIKeyboardWillHideNotification. I'm sure I'm doing something wrong, but honestly I can't figure it out.I have two view controllers let's call them A and B
(1) in A I show a popOver containing a textField
(2) in B there is an UITextView used for simple text editing
I Have to manage the keyboard in A and in B to scroll the content hidden by the keyboard. I know how to reposition the content. What I need is a way to have different behavior on the same notifications types that in my are UIKeyboardWill(Show/Hide)Notification.
What I've done so far :
(1) I've added this code in each controller
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidAppear:)
name:UIKeyboardWillShowNotification
object:self.view.window
as I said I've added this code to A and B, but doesn't work as I expected. For instance
When I click inside the textView two methods are triggered the keyboardDidAppear of A and the keyboardDidAppear of B, the same happens with the UIKeyboardWillHideNotification.
I'm sure I'm doing something wrong, but honestly I can't figure it out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我解决了这个问题,改变了我注册通知的位置。为了确保只有 viewController 可见是接收通知的控制器,我在 vieWillAppear 中注册了通知,并在 viewWillDisappear 中删除了通知。
I solved this problem changing the place in wich I register for the notification. To make sure that only the viewController visible is the controller that receive the notification I register for the notification in vieWillAppear and remove the notification in viewWillDisappear.
你的语法也有点混乱,你需要在@后面添加单词选择器...
Your syntax is a bit messed too, you need to add the word selector after the @ ...