Patrick Patrick - 5 months ago 15
Objective-C Question

The UISearchBar doesn't dismiss the keyboard when enter is pressed

The

UISearchBar
doesn't dismiss the keyboard when enter is pressed, or the user touch somewhere else.

I need to use the remove keyboard button on the bottom right of the iOS keyboard in order to remove the keyboard and invoke:

- (void)searchBarTextDidEndEditing:(UISearchBar *)aSearchBar


How can I fix it?

Answer
- (void)searchBarTextDidEndEditing:(UISearchBar *)aSearchBar {
    [aSearchBar resignFirstResponder];
}

Also you have to set delegate for the UISearchBar: UISearchBarDelegate

It should work.

Here is sample code http://developer.apple.com/library/ios/#samplecode/ToolbarSearch/Listings/ToolbarSearch_APLToolbarSearchViewController_m.html#//apple_ref/doc/uid/DTS40009461-ToolbarSearch_APLToolbarSearchViewController_m-DontLinkElementID_9

Another option is searchBarSearchButtonClicked we can use.

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
    // You can write search code Here
}