UIKeyboardWillShowNotification, UIKeyboardWillHideNotification and NSNotificationCenter problem between iOS versions UIKeyboardWillShowNotification, UIKeyboardWillHideNotification and NSNotificationCenter problem between iOS versions objective-c objective-c

UIKeyboardWillShowNotification, UIKeyboardWillHideNotification and NSNotificationCenter problem between iOS versions


What you can do is set the textfield's/textview's delegate to the current view controller and implement these 2 methods

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{    _keyboardWillHide = NO;    return YES;}- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{    _keyboardWillHide = NO;    return YES;    }

After that in your method that get's triggered by the UIKeyboardWillHideNotification notification you can do something like

if (_keyboardWillHide) {    // No other textfield/textview was selected so you can animate the tableView    ...}_keyBoardWillHide = YES;

Let me know if that works for you.


Rather than avoid the notifications, you can set an NSTimer for 0.1 second to do your animations in one, and in the other, cancel the timer, that way if you get UIKeyboardWillHide and UIKeyboardWillShow both at once, you'll get a chance to cancel the timer. If you don't get both, the timer will reach zero and the animations will be carried out.


Consider using the UITextFieldDelegate protocol. The method textFieldShouldBeginEditing: will fire off before the notification and it will fire off everytime you go into the text field.