2017-01-10 8 views
3

私は同様の問題と解決策を読んでいます。しかし、誰も私の問題を解決することはできません。カスタム検索コントローラとカスタム検索バーを使用しています。func updateSearchResults(searchController:UISearchController)が呼び出されていません。updateSearchResults()が呼び出されない

var customSearchController: CustomSearchViewController! 

CustomSearchViewController:のviewDidLoadでは、()

customSearchController = CustomSearchViewController(searchResultsController: ***nil***, searchBarFrame: CGRect(x: 0.0, y: 0.0, width: searchTableView.frame.size.width, height: 44.0), searchBarFont: UIFont(name: "HelveticaNeue", size: 16.0)!, searchBarTextColor: UIColor.purple, searchBarTintColor: UIColor.white) 

customSearchController.searchResultsUpdater = self 
customSearchController.definesPresentationContext = true 
customSearchController.customSearchBar.placeholder = "What are you looking for?" 
customSearchController.customSearchBar.backgroundColor = UIColor.white 
customSearchController.customSearchBar.sizeToFit() 
customSearchController.customSearchBar.resignFirstResponder() 
customSearchController.customSearchBar.showsCancelButton = true 
customSearchController.customSearchBar.delegate = self 

と呼ば得ていない: FUNCの検索バーを::(

func updateSearchResults(for searchController: UISearchController) { 
    filtered.removeAll() 
    filtered = searchArray.filter({ (text) -> Bool in 
     let tmp: NSString = text as NSString 
     let range = tmp.range(of: customSearchController.customSearchBar.text!, options: NSString.CompareOptions.caseInsensitive) 
     return range.location != NSNotFound 
    }) 
    self.searchTableView.reloadData() 
} 

答えて

4

時間苦労した後、私が使用してそれを解決することができました(_ searchBar:UISearchBar、textDidChange searchText:String) - UISearchBarDelegateデリゲートメソッド

UpdateSearchResults()の代わりに

- UISearchResultsデリゲートメソッドを更新する

希望する人に役立つことを願っています:)

関連する問題