gpt4 book ai didi

ios - 如何让 UISearchController 等到搜索被点击

转载 作者:可可西里 更新时间:2023-11-01 00:11:16 24 4
gpt4 key购买 nike

我正在尝试在我的 SWIFT 代码中实现搜索。我希望它在执行任何操作之前等到单击搜索按钮。到目前为止我所拥有的。

func updateSearchResultsForSearchController(searchController: UISearchController)
{
self.filteredCats.removeAll(keepCapacity: false)
filteredCats = art.filter{
$0.sarticleTitle.lowercaseString.rangeOfString(searchController.searchBar.text!.lowercaseString) != nil
}
print(searchController.searchBar.text)
self.tableView.reloadData()
}

它会在用户输入内容后打印出所有信息。我希望它等到单击搜索按钮或用户完成所有输入时。

最佳答案

你应该像这样设置委托(delegate)你的 View Controller 。

var resultSearchController = UISearchController()
resultSearchController.searchBar.delegate = self

extension ViewController: UISearchBarDelegate {
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("search button click")
}
}

关于ios - 如何让 UISearchController 等到搜索被点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34594743/

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