iphoneiosuisearchbarresignfirstresponder

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.


Solution

  • you can do this in appDelegate....

    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        [self.window endEditing:YES];
    }