iOS UISearchController Implementation

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

First, make your class comply with the UISearchResultsUpdating protocol.

class MyTableViewController: UITableViewController, UISearchResultsUpdating {}

Add the search controller property:

class MyTableViewController: UTableViewController, UISearchResultsUpdating {
    let searchController = UISearchController(searchResultsController: nil)
}

Add the search bar:

override func viewDidLoad() {
    super.viewDidLoad()

    searchController.searchResultsUpdater = self
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.sizeToFit()
    self.tableView.tableHeaderView = searchController.searchBar
}

And finally, implement the updateSearchResultsForSearchController method that comes from the UISearchResultsUpdating protocol:

func updateSearchResultsForSearchController(searchController: UISearchController) {

}


Got any iOS Question?