Codey Codey - 23 days ago 7
Swift Question

UISearchController without use of Navigation Controller

Is it possible to use the

UISearchController
without the
SearchBar
being displayed in the
Navigation Controller
? I basically want the
SearchBar
to stay on the screen and display the TableView beneath it:

Mockup

What I was trying to do is this:
I've created a
UITableViewController
on the storyboard and linked it to the custom
NPTableViewController
class. Then I did this:

let resultsTable = storyboard!.instantiateViewController(withIdentifier: "LocationSearch") as! NPTableViewController
searchController = UISearchController(searchResultsController: resultsTable)
searchController?.searchResultsUpdater = resultsTable

let searchBar = searchController!.searchBar
searchBar.sizeToFit()
searchBar.placeholder = "Search for places"
searchBar.frame.origin.y = 100.0
self.view.addSubview(searchBar)


Now when I run it, the
searchBar
is displayed but when I click on it the background dims, the
searchBar
disappears my
resultsTable
is also not displayed.

Answer

The solution I came up with is actually very simple. Instead of using UISearchController, I used a normal UISeachBar and UITableView. Since UISearchController doesn't do so much to help you, the work is pretty much the same if I kind of build my own SearchController.