I've added the UISearchBar
button inside the UIBarButtonItem
inside the toolbar button.
In the below form:
// search bar
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 260, 44)];
UIBarButtonItem *searchBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:searchBar];
[searchBar release];
[buttons addObject:searchBarButtonItem];
Now the problem in when I click on the UISearchBar
keyboard appears. I'd like to hide the keyboard on clicking in enter or search button. How can i do this?
Implement a method from UISearchBarDelegate
:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[searchBar resignFirstResponder];
}
For Swift
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
searchBar.resignFirstResponder()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With