我正在尝试使用 UISearchBarDelegate 的委托(delegate)函数 searchBarSearchButtonClicked。我的搜索栏位于 UITableViewController 的标题中。请问有人可以建议吗?
class MySearchTableViewController: UITableViewController, UISearchBarDelegate{
override func viewDidLoad() {
super.viewDidLoad()
}
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
print("clicked!")
}
最佳答案
您需要设置搜索栏的委托(delegate)。
(1) mySearchBar.delegate = self
(2) 在 Storyboard中,ctrl+拖动搜索栏到 viewController 并选择委托(delegate)。
关于ios - UISearchBarDelegate 函数 -searchBarSearchButtonClicked 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44201729/