keyboardWillShow调用了两次 [英] keyboardWillShow called twice
问题描述
我有键盘通知的视图,例如 keyboardWillShow
和 keyboardWillHide
I have a view with keyboard notifications such as keyboardWillShow
and keyboardWillHide
我使用的通知处理的所有代码都来自Apple的示例代码KeyboardAccessory
All the codes handles with the notification I use is taken from Apple's sample code "KeyboardAccessory"
当我第一次进入此视图时,一切正常。
When I first enter this view, everything works fine.
但是当我从子视图返回此视图时,每次我点按一个按钮说:
But when I return to this view from its subviews, every time I tap a button that says:
[myTextField becomeFirstResponder];
keyboardWillShow
和 keyboardWillHide
每次都会调用两次方法。
the keyboardWillShow
and keyboardWillHide
methods will be called twice every time.
这真的令人困惑,
有人可以帮我吗?
非常感谢!
推荐答案
您可能希望发布您的代码。
You might want to post your code.
如果您的方法被调用两次,很可能是您多次注册键盘通知而不是在删除观察者时你认为你是。
If your methods are being called twice, most likely, you are registering for the keyboard notifications multiple times and not removing the observer when you think you are.
在viewWillAppear中添加你的观察者:并在viewWillDisappear中删除它:看看会发生什么。
Add your observer in viewWillAppear: and remove it in viewWillDisappear: and see what happens.
这篇关于keyboardWillShow调用了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!