2

我有两个视图控制器,我们称它们为 A 和 B

(1) 在 AI 中显示一个包含 textField 的 popOver
(2) 在 B 中有一个 UITextView 用于简单的文本编辑

我必须管理 A 和 B 中的键盘以滚动键盘隐藏的内容。我知道如何重新定位内容。我需要的是一种在我的 UIKeyboardWill(Show/Hide)Notification 相同的通知类型上具有不同行为的方法。
到目前为止我所做的:
(1)我在每个控制器中添加了这段代码


    [[NSNotificationCenter defaultCenter] addObserver:self
                                  selector:@selector(keyboardDidAppear:)
                                      name:UIKeyboardWillShowNotification
                                    object:self.view.window
正如我所说,我已将此代码添加到 A 和 B,但没有按预期工作。例如,当我在 textView 内单击时,触发了 A 的keyboardDidAppear 和 B 的keyboardDidAppear 两个方法,UIKeyboardWillHideNotification 也会发生同样的情况。我确定我做错了什么,但老实说我无法弄清楚。

4

2 回答 2

3

我解决了这个问题,改变了我注册通知的地方。为了确保只有可见的 viewController 是接收通知的控制器,我在 vieWillAppear 中注册通知并在 viewWillDisappear 中删除通知。

于 2011-02-25T07:37:14.690 回答
0

Your syntax is a bit messed too, you need to add the word selector after the @ ...

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardDidAppear:)
                                                 name:UIKeyboardWillShowNotification
                                               object:self.view.window];
于 2013-03-06T16:20:10.820 回答