1

I am using UISearchController (not UISearchDisplayController), i wanted to show a separate view when search is active. I dont want to use the current view.

Tried with self.searchController = UISearchController(searchResultsController: self.resultsController ). But this doesn't show anything.

Even tried this

 func presentSearchController(_ searchController: UISearchController) {
     DispatchQueue.main.async {
         searchController.searchResultsController?.view.isHidden = false
     }
 }

 func didPresentSearchController(_ searchController: UISearchController) {
     searchController.searchResultsController?.view.isHidden = false
 }

My default table data before search is active is as below, i want this table to hide and show separate view and pass the typed keyword to that new view. How can i achieve this?

enter image description here

saurabh
  • 6,687
  • 7
  • 42
  • 63
Stephen
  • 3,359
  • 4
  • 20
  • 30

1 Answers1

1

As there is no direct segue to viewController, we need to explicitly refer the viewController we wanted to use.

I have used the below code and it loads my new controller when my searchBar is active.

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    self.resultsController = storyboard.instantiateViewController(withIdentifier: "searchResults") as! SearchResultsTableViewController
    self.searchController = UISearchController(searchResultsController: self.resultsController )

Let me know if any better approach is available.

Stephen
  • 3,359
  • 4
  • 20
  • 30