Cancel Button in UISearchController

kAiN picture kAiN · Oct 16, 2014 · Viewed 14.1k times · Source

In my project I'm using a UITableViewController with an internal UISearchController to filter the data in my tableView.

I have no problem to filter the data but I need to make a date of my tableView reload when I click on the CANCEL button UISearchController but I can not find the delegate method for this ...

Can you help me understand how to solve this problem?

Answer

Gargoyle picture Gargoyle · Oct 21, 2014

You need to set the UISearchController searchBar's delegate. Once you have done this, the addition of the delegate method searchBarCancelButtonClicked: will properly be called.

self.searchController.searchBar.delegate = self;

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
}