Hello I have a searchController which disappears on click on one of the search items that appeared before the new view displays. What I would like is for the search controller to stay active so when the user goes back to the view they still see the list of results. currently I display the search controller with a present function. Any ideas how to stop this from leaving the screen? Thank you in advance!!
MainViewController:
func searchButtonClicked(){
self.searchController?.isActive = true
self.searchController?.searchBar.becomeFirstResponder()
if let controller = self.searchController {
present(controller, animated: true, completion: nil)
}
}
func searchItemClicked(){
self.searchController?.isActive = false
//set up detail controller and push
let vc : detailViewController =self.storyboard?.instantiateViewController(withIdentifier:"DetailViewController")
self.navigationController?.pushViewController(vc, animated: true)
}
func setupSearch(){
self.searchController = UISearchController.init(searchResultsController: searchResultsCustomController)
self.searchController?.obscuresBackgroundDuringPresentation = true
self.searchController?.searchBar.delegate = self
self.searchController?.searchBar.showsCancelButton = true
self.searchController?.searchBar.placeholder = "Search for people or places"
}
EDIT: To add more information regarding this error. The navigation bar has a search button which the user clicks to do a search. From here the searchController is started and a search bar appears. Upon entering credentials for the search the table view appears with results. If the user clicks on one of this results, the table view and the search bar disappear by going up as if I pressed the cancel button, and then the screen is pushed to the detail view controller.
For anyone running into this issue all you have to do is add the following line of code on your viewdidload function:
self.definesPresentationContext = true