I detect when the keyboard will show with the below code. However, when I push to another screen using pushViewController and open the keyboard in that screen, keyboardWillShow is getting called! Is this really correct?
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
// register for keyboard notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
Yes, this is correct behavior.
Since the view that pushes the other view is still alive and the notifications are app wide.
You could remove the notification in the:
And if you want to set the observer then place you code from viewDidLoad to viewWillAppear:(BOOL)animated: