2

I would like uisearchcontroller to start searching after I type at least three characters in search bar. So, what should I do for that ?

    func configureSearchController() {
    // Initialize and perform a minimum configuration to the search controller.
    searchController = UISearchController(searchResultsController: nil)
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.placeholder = "Search"
    searchController.searchBar.delegate = self
    searchController.searchBar.sizeToFit()

    let textFieldInsideSearchBar = searchController.searchBar.valueForKey("searchField") as! UITextField
    textFieldInsideSearchBar.font = UIFont(name: "Bauhaus", size: 19)


   searchController.searchBar.setImage(UIImage(named: "searchikon"), forSearchBarIcon: UISearchBarIcon.Search, state: UIControlState.Normal);

    // Place the search bar view to the tableview headerview.
    TableView.tableHeaderView = searchController.searchBar
OzzY
  • 221
  • 5
  • 16
  • Possibly this obj-c solution can be of help: http://stackoverflow.com/questions/9721668/how-can-i-disable-enable-uisearchbar-keyboards-search-button/9722139#9722139 – dfrib Jan 29 '16 at 22:59

2 Answers2

2

All you need to is add the single required method for the UISearchController.

func updateSearchResultsForSearchController(searchController: UISearchController)     {   
    if searchController.searchBar.text?.characters.count > 2 {
        // Filter your search results here
    }

}
Hunter Monk
  • 1,967
  • 1
  • 14
  • 25
0

You will want to check the the length of the characters in an event which checks the change in the text field:

nameOfString.characters.count
ksa_coder
  • 1,393
  • 3
  • 15
  • 38