我已经在SO上阅读了类似的问题和解决方案.但似乎没有一个能解决我的问题.我正在使用自定义搜索控制器和自定义搜索栏,并且没有调用func updateSearchResults(对于searchController:UISearchController).
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 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() }
Molly.. 10
经过几个小时的努力,我能够通过使用:func searchBar(_ searchBar:UISearchBar,textDidChange searchText:String) - UISearchBarDelegate委托方法来解决它.
而不是updateSearchResults() - UISearchResultsUpdating委托方法
希望它可以帮助别人:)
经过几个小时的努力,我能够通过使用:func searchBar(_ searchBar:UISearchBar,textDidChange searchText:String) - UISearchBarDelegate委托方法来解决它.
而不是updateSearchResults() - UISearchResultsUpdating委托方法
希望它可以帮助别人:)
我必须UISearchController
在类范围内声明实例。看到这个答案。/sf/ask/17360801/
以前我在viewDidLoad
方法中声明了它