Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger cancel button in UISearchBar?

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.

like image 633
Marckaraujo Avatar asked Apr 11 '13 20:04

Marckaraujo


2 Answers

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.

like image 135
Martin R Avatar answered Sep 22 '22 19:09

Martin R


For the new UISearchController (introduced in 2014 with iOS 8) you can call:

[self.searchController setActive:FALSE]; 

or

self.searchController.active = FALSE; 

(No flag for animation, I've found it always animates.)

like image 42
Nick Avatar answered Sep 25 '22 19:09

Nick