keyboardWillShow called twice

Wang Liang picture Wang Liang · Nov 10, 2011 · Viewed 9.4k times · Source

I have a view with keyboard notifications such as keyboardWillShow and keyboardWillHide

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];

the keyboardWillShow and keyboardWillHide methods will be called twice every time.

It's really confusing,

Could anyone helps me with this?

really appreciate!

Answer

Eric picture Eric · Nov 10, 2011

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.

Add your observer in viewWillAppear: and remove it in viewWillDisappear: and see what happens.