I use the very simple two lines method to solve the issue
First write a Bool isKeyBoardHide.
Then in ViewDidLoad Write this code
// Listen for keyboard appearances and disappearances
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
Write these two methods to update bool about current status
- (void)keyboardDidShow: (NSNotification *) notif{
isKeyBoardHide = NO;
}
- (void)keyboardDidHide: (NSNotification *) notif{
isKeyBoardHide = YES;
}
When you want to check just implement that code
if(!isKeyBoardHide) {
// Dismiss Keyboard
[self.view endEditing:YES]
} else {
//keyboard is already hidden
}
Very simple and easy way to solve this crash.