iOS - NSNotificationCenter 多个UIKeyboard通知

发布于 2024-10-15 19:48:05 字数 890 浏览 2 评论 0原文

我有两个视图控制器,我们称它们为 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 技术交流群。

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

发布评论

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

评论(2

○愚か者の日 2024-10-22 19:48:05

我解决了这个问题,改变了我注册通知的位置。为了确保只有 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.

桜花祭 2024-10-22 19:48:05

你的语法也有点混乱,你需要在@后面添加单词选择器...

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(keyboardDidAppear:)
                                                 name:UIKeyboardWillShowNotification
                                               object:self.view.window];

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