我正在尝试在我的 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/