Chenggong Jin Chenggong Jin - 11 months ago 106
Objective-C Question

UISearchbar keyboard search button Action

I'm using UISearchbar. when I input text on UISearchbar, the keyboard shows. At that time, keyboard return key is "Search".
I want to implement event when I press the keyboard search button.
How can I implement the action?
On UItextfield, it has
-(BOOL)textFieldShouldReturn:(UITextField *)textField{}

But on UISearchbar, it doesn't have return action.

Thank you for your helping.


Add UISearchBarDelegate in .h

Also set SearchBar's object delegate to self.

Add this to the UISearchBarDelegate's method:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
    [searchBar resignFirstResponder];
    // Do the search...