searchBarCancelButtonClicked delegate method is not called. Is there any way to call?

Szakma picture Szakma · Dec 6, 2010 · Viewed 12.7k times · Source

UIViewController to implement a view to placing an UITableView UISearchBar and being implemented. But you can not call searchBarCancelButtonClicked. Do not know what the reason.

Answer

Chris Balavessov picture Chris Balavessov · Jan 19, 2016

The reason why searchBarCancelButtonClicked does not fire may be because your UISearchBar does not show the Cancel button. You can display the Cancel button like this:

searchBar.showsCancelButton = true

I had the same problem and making the Cancel button show made searchBarCancelButtonClicked fire as expected.