Skip to content

Instantly share code, notes, and snippets.

@muizidn
Created December 6, 2017 10:18
Show Gist options
  • Save muizidn/1c6c35192b545b384cbded20fec0c536 to your computer and use it in GitHub Desktop.
Save muizidn/1c6c35192b545b384cbded20fec0c536 to your computer and use it in GitHub Desktop.
This can be used to make search controller in header of tableView
// UIViewController class conforms UISearchResultUpdating
// MARK: Search Controller
func configureSearchController() {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
}
func filterContentForSearchText(_ string: String, scope: String = "All" ) {
filteredSearch = dropboxListFolder!.filter { item in
return item.name.lowercased().contains(string.lowercased())
}
tableView.reloadData()
}
// Conformity
func updateSearchResults(for searchController: UISearchController) {
filterContentForSearchText(searchController.searchBar.text!)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment