模式对话框后的键盘通知
我有一个 UITableViewController,其中一些行包含文本字段,其他行显示模式视图。我在 viewWillAppear
中注册了 UIKeyboardWillShowNotification
和 UIKeyboardWillHideNotification
,并在 viewWillDisappear
中取消注册。
接下来我这样做: - 单击文本字段。我收到 UIKeyboardWillShowNotification
,调整表格大小以容纳键盘。 - 选择显示模式视图控制器的行,我收到 UIKeyboardWillHideNotification
,并调用 viewWillDisappear
。 - 关闭模态视图控制器后,调用 viewWillAppear
,并且我得到一个 UIKeyboardWillShowNotification
。但没有显示键盘。所以我的桌子调整了大小,但没有出现键盘。
这是 SDK 中的错误吗?或者这是常见的行为而我错过了一些东西?
I have a UITableViewController
with some rows containing textfields, and other rows that show a modal view. I register for the UIKeyboardWillShowNotification
and UIKeyboardWillHideNotification
in viewWillAppear
, and unregister in viewWillDisappear
.
Next I do this:
- click on a textfield. I get the UIKeyboardWillShowNotification
, resize the table to have place for the keyboard.
- select a row that presents a modal view controller, I receive the UIKeyboardWillHideNotification
, and viewWillDisappear
is called.
- after closing the modal view controller, viewWillAppear
is called, and I get a UIKeyboardWillShowNotification
. But no keyboard is shown. So my table is resized, but no keyboard appears.
Is this a bug in the SDK? Or is it common behavior and I'm missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的逻辑对我来说是正确的。但我想知道每次
viewWillAppear
注册UIKeyboardWillHideNotification
可能会出现问题。尝试在viewDidLoad
中仅注册一次并在dealloc
中取消订阅。我在想,也许当您在关闭模态视图后再次注册时,通知中心会向您发送旧通知。如果您注册一次通知,您将不会收到比发布更多的通知。Your logic seams correct to me. But I wonder about a possible problem with registering for a
UIKeyboardWillHideNotification
every time yourviewWillAppear
. Try to register only once inviewDidLoad
and unsubscribe indealloc
. I am thinking that maybe when you register again after you dismiss the modal view the Notification Center sends you an old notification. If you register once for a notification you will not get it more then it is posted.