Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active April 23, 2016 01:47
Show Gist options
  • Save KentarouKanno/0f2be9b24e71075b022a7c49e466e37f to your computer and use it in GitHub Desktop.
Save KentarouKanno/0f2be9b24e71075b022a7c49e466e37f to your computer and use it in GitHub Desktop.
UISearchController

UISearchController

import UIKit

class ViewController: UIViewController, UISearchResultsUpdating {
    
    var searchController = UISearchController(searchResultsController: nil)

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }

    // SearchBarに文字列を入力された時に呼ばれる
    func updateSearchResultsForSearchController(searchController: UISearchController) {
        print(searchController.searchBar.text)
    }

    @IBAction func searchButton(sender: UIBarButtonItem) {
        // SearchController Setting
        searchController.searchResultsUpdater = self
        searchController.hidesNavigationBarDuringPresentation = false
        searchController.dimsBackgroundDuringPresentation = true
        searchController.searchBar.searchBarStyle = UISearchBarStyle.Prominent
        searchController.searchBar.sizeToFit()
        presentViewController(searchController, animated: true, completion: nil)
    }
}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment