我已经阅读过类似的问题和解决方案。但是似乎没有人能解决我的问题。我正在使用自定义搜索 Controller 和自定义搜索栏,并且未调用 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()
}
最佳答案
经过几个小时的努力,我能够通过使用以下方法解决该问题:
func searchBar(_ searchBar:UISearchBar,textDidChange searchText:String)-UISearchBarDelegate委托(delegate)方法。
而不是updateSearchResults()-UISearchResultsUpdating委托(delegate)方法
希望它可以帮助某人:)
关于search - updateSearchResults()没有被调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41560794/