问题描述
我有一个带有键盘通知的视图,例如 keyboardWillShow
和 keyboardWillHide
I have a view with keyboard notifications such as keyboardWillShow
and keyboardWillHide
我使用的通知处理的所有代码均取自 Apple 的示例代码 "键盘配件"
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.
真的很纠结,
有人能帮我解决这个问题吗?
Could anyone helps me with this?
真的很感谢!
推荐答案
您可能想要发布您的代码.
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 调用了两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!