How do you fire the UISearchController? (iOS 8 onwards)

This should be trivial, but I cannot find how you should programmatically ignore the UISearchController?

Please note that this is a new UISearchController (introduced in 2014 with iOS 8) and not a UISearchDisplayController.

So far i have

// Dismiss the search tableview searchController.dismissViewControllerAnimated() // Clear the Search bar text searchController.active = false 

But I still have a cancel button and can't get rid of it.

+46
swift uisearchcontroller
Feb 10 '15 at 17:48
source share
4 answers

OK, so after more thorough testing, you just have to install:

 searchController.active = false 

This is the first thing I tried, but I named it in one of the UISearchControllerDelegate methods that did not work (probably should have called it with dispatch_async (the halbano answer seems to confirm this)).

In any case, since I could not find this answer on the network, I answer my question, I hope this helps someone.

+106
Feb 10 '15 at 17:48
source share

Do you have this problem when you try to reject the search controller after switching to another mode? I also ran into this problem. I think you can use

 self.definesPresentationContext = true 

in the view controller, which represents the UISearchController according to this message, the UISearchController, which does not reject when you click the View button . This works for me.

+12
Dec 02 '15 at 6:32
source share

I represented the mine in the navigation bar. The code that works for me was:

 - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar{ dispatch_async(dispatch_get_main_queue(), ^{ [self.searchController setActive:NO]; self.navigationController.navigationBar.topItem.title = @"MYTITLE".uppercaseString; self.navigationItem.titleView = nil; }); } 

Hope this helps someone.

+9
Dec 12 '15 at 23:19
source share

I had this problem using search andactionController, resolved after including the line: self.dismissViewControllerAnimated (false, completion: zero)

Open the interaction and clear the search unchanged in the delegate.

+1
Oct 27 '16 at 13:18
source share



All Articles