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.
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With