Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone: Hide Keyboard on App Did Enter Background or View Did Disappear

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.

like image 554
Dave Avatar asked Aug 18 '12 12:08

Dave


People also ask

Which function hides the keyboard in IOS?

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.

How do you dismiss a keyboard?

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.

How do I close the keyboard on IOS?

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).


1 Answers

you can do this in appDelegate....

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    [self.window endEditing:YES];
}
like image 185
Rajneesh071 Avatar answered Sep 21 '22 01:09

Rajneesh071