Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 219
Codey Avatar asked Oct 30 '22 17:10

Codey


1 Answers

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.

like image 60
Codey Avatar answered Nov 20 '22 18:11

Codey