gpt4 book ai didi

ios - Uisearchresultsupdating 协议(protocol)未收到任何数据

转载 作者:行者123 更新时间:2023-11-30 10:53:41 26 4
gpt4 key购买 nike

当我开始在搜索栏上输入时,我没有通过我的协议(protocol)收到任何数据。我的目标是在搜索 Controller 中的搜索栏上开始输入时获取数据。

代码:

class FirstViewController:UIViewController,UISearchResultsUpdating{
func updateSearchResults(for searchController: UISearchController) {
self.labels.text="sd"
}

override func viewDidLoad() {
super.viewDidLoad()
let searchcontrol=UISearchController(searchResultsController:self)

searchcontrol.searchResultsUpdater=self
let subView = UIView(frame: CGRect(x: 0, y: 65.0, width: 350.0, height: 45.0))

subView.addSubview((searchcontrol.searchBar))
searchcontrol.searchBar.sizeToFit()
searchcontrol.hidesNavigationBarDuringPresentation = false
view.addSubview(subView)
}
}

最佳答案

正如rmaddy所说,尝试这样的事情:

class FirstViewController: UIViewController {

let searchController = UISearchController(searchResultsController: nil)

override func viewDidLoad() {
super.viewDidLoad()

searchcontrol.searchResultsUpdater=self
let subView = UIView(frame: CGRect(x: 0, y: 65.0, width: 350.0, height: 45.0))

subView.addSubview((searchcontrol.searchBar))
searchcontrol.searchBar.sizeToFit()
searchcontrol.hidesNavigationBarDuringPresentation = false
view.addSubview(subView)
}

}

extension FirstViewController: UISearchResultsUpdating{

func updateSearchResults(for searchController: UISearchController) {
self.labels.text="sd"
}

}

关于ios - Uisearchresultsupdating 协议(protocol)未收到任何数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54187138/

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