Created
December 6, 2017 10:18
-
-
Save muizidn/1c6c35192b545b384cbded20fec0c536 to your computer and use it in GitHub Desktop.
This can be used to make search controller in header of tableView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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