Last active
May 24, 2016 18:10
-
-
Save fongd/9501c346137d4ed9795c4dc6a8c465ef to your computer and use it in GitHub Desktop.
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
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