Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always show the cancel button in a UISearchBar

I use a table view with a UISearchDisplayController in conjunction with a UISearchBar. The search bar automatically hides the cancel button when inappropriate, but I'm using the view controller in a modal state - so I would like to always show the cancel button and use it to pop the modal view controller when the search is cancelled.

Is there a way to force the cancel button to stay visible without creating a custom search bar?

like image 549
Era Avatar asked Aug 25 '11 13:08

Era


1 Answers

you should use the display delegate

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller 
{
    controller.searchBar.showsCancelButton = YES;
}
like image 86
Omar Freewan Avatar answered Nov 02 '22 22:11

Omar Freewan