How to trigger cancel button in UISearchBar?

Marckaraujo picture Marckaraujo · Apr 11, 2013 · Viewed 31.1k times · Source

How to trigger programmatically cancel button in UISearchBar, like if you have tapped cancel button?

I have a UISearchBar in the top of a UITableView and after a search, when someone select a row, I want to trigger programmatically cancel button in the UISearchBar?

EDIT: Without user interaction.

Answer

Martin R picture Martin R · Apr 11, 2013

For a view controller using a search display controller, you can set

self.searchDisplayController.active = NO;
// or:
[self.searchDisplayController setActive:NO animated:YES];

to dismiss the search interface.