Skip to content

Instantly share code, notes, and snippets.

@fongd
Last active May 24, 2016 18:10
Show Gist options
  • Select an option

  • Save fongd/9501c346137d4ed9795c4dc6a8c465ef to your computer and use it in GitHub Desktop.

Select an option

Save fongd/9501c346137d4ed9795c4dc6a8c465ef to your computer and use it in GitHub Desktop.

Revisions

  1. fongd revised this gist May 24, 2016. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    override func viewDidLoad() {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("Search")

    @@ -12,7 +13,7 @@

    let resultsController = SearchViewController()
    self.searchController.searchResultsUpdater = resultsController

    }

    ...

  2. fongd created this gist May 24, 2016.
    31 changes: 31 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    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()
    }
    }