In my code this is how I setup UISearchController
:
searchResultController = storyboard!.instantiateViewControllerWithIdentifier(DBSearchResultControllerIdentifier) as! DBSearchResultController
searchController = UISearchController(searchResultsController: searchResultController)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchResultController.tableView.tableHeaderView = searchController.searchBar
on some action all I do is:
@IBAction func cityButtonTapped(sender: UIButton) {
searchController.active = true
}
But then I have an error:
Application tried to present modal view controller on itself. Presenting controller is
UISearchController: 0x7f9a0c04a6a0
The apple documentation for UISearchController
clearly says the following things:
active
property to YES performs a default presentation of
the search controller.searchResultsController
parameter to nil
to display the
search results in the same view that you are searching.So it looks like you are using your current view controller itself as your searchResultsController
and hence when you try to set active
to YES, it tries to modally present the your current view on itself and hence the error.
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