Skip to content

Instantly share code, notes, and snippets.

@fongd
Last active May 24, 2016 18:10
Show Gist options
  • Save fongd/9501c346137d4ed9795c4dc6a8c465ef to your computer and use it in GitHub Desktop.
Save fongd/9501c346137d4ed9795c4dc6a8c465ef to your computer and use it in GitHub Desktop.
override func viewDidLoad() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("Search")
self.searchController = UISearchController(searchResultsController: vc)
self.searchView.addSubview(searchController.searchBar)
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.searchBar.searchBarStyle = .Minimal
self.searchController.searchBar.sizeToFit()
self.navigationItem.titleView = searchController.searchBar
self.definesPresentationContext = true
let resultsController = SearchViewController()
self.searchController.searchResultsUpdater = resultsController
}
...
extension SearchViewController: UISearchResultsUpdating {
func updateSearchResultsForSearchController(searchController: UISearchController) {
let searchString = searchController.searchBar.text
filteredArray = dataArray.filter({ (country) -> Bool in
let countryText: NSString = country
return (countryText.rangeOfString(searchString!, options: NSStringCompareOptions.CaseInsensitiveSearch).location) != NSNotFound
})
tblSearchResults.reloadData()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment