I have a view with a UISearchBar in it. However, when the "X" button in the searchbar is clicked, it removes the keyboard but doesn't remove the text in the textfield of the searchbar. What I want is this: When the user clicks the x button, the text in the textfield is reset but the keyboard stays up.
How can I do this?
This seems to do the trick for me. Make sure your View Controller is a UISearchBarDelegate
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
searchBar.text = @"";
}
Just set the text to nil in searchBarCancelButtonClicked delegate method :
searchBar.text = nil;
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