Chenggong Jin Chenggong Jin - 1 year ago 151
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.

Answer Source

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...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download