I have a UISearchBar which when clicked, shows the keyboard. However if the user presses the home button while the keyboard is shown and then goes back into the app, the keyboard is still visible. How can I hide th keyboard when the app closes/enters background?
I've tried the following in viewDidDisappear:
[eventSearchBar resignFirstResponder];
[eventSearchBar endEditing:YES];
I've also tried this in the delegate in appDidEnterBackground:
[self.rootController.navigationController.view endEditing:YES];
None of these worked.
The keyboard appears on screen when we are typing in a text Field or textView. We need to make use of internal function according to the text field. This code will hide the keyboard when ever called, we may call this on an action for a button or for gesture recognizer.
Android devices have a solution; press the physical back button (provided on some mobile phones) or the soft key back button, and it closes the keyboard.
You can still do the down swipe above the keyboard, which is standard in the OS, but you can also just use the keyboard button on the right of the bar (iPhone), or use the standard hide-keyboard button on the iPad (bottom-right).
you can do this in appDelegate....
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self.window endEditing:YES];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With