0
votes

I have a UISearchBar with a cancel button. User types and hit search button. The keyboard disappear. If the user hit the cancel button, the keyboard appear and then if user hit cancel again, delegate method is called :

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

Why ?

I just want a direct action on cancel button without any keyboard showing up.

1
so you want the delegate method to be called on first click on cancel button ?Teja Nandamuri
yes without any keyboard showing. It seems complicated without creating a custom UI componentPierre
I've recently implemented a UISearchBar for the app I'm working on. In my case, when I hit search the keyboard is dismissed and Cancel button is disabled. Is the button enabled in your case?mxmlc
Button is only enabled when keyboard is present.Pierre
I just created a fresh project with just a UISearchBar and a UITableView. Loaded a country list and override some methods as expected by the delegates. When I click Search button the keyboard is dismissed but the Cancel button is still showing so in just one tap it works. Are your UISearchBar customized?mxmlc

1 Answers

0
votes

You can manually manage whether the cancel button is shown or hidden with the showsCancelButton property and implementing the desired behavior in the following delegate methods.

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar