gpt4 book ai didi

search - updateSearchResults() 没有被调用

转载 作者:行者123 更新时间:2023-12-04 09:58:14 25 4
gpt4 key购买 nike

我已经阅读了关于 SO 的类似问题和解决方案。但似乎没有一个能解决我的问题。我正在使用自定义搜索 Controller 和自定义搜索栏和 func updateSearchResults(for 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()
}

最佳答案

我必须声明 UISearchController类范围内的实例。看到这个答案。 https://stackoverflow.com/a/46781890/1511978

以前我在 viewDidLoad 中声明了它。方法

关于search - updateSearchResults() 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41560794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com