ios - UISearchBarDelegate 函数 -searchBarSearchButtonClicked 不工作

标签 ios swift

我正在尝试使用 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)。

enter image description here

关于ios - UISearchBarDelegate 函数 -searchBarSearchButtonClicked 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44201729/

相关文章:

ios - 如何从设备中的图像读取二维码

ios - 用户拒绝定位服务后再次请求权限?

swift - 有更好的方法来使用这个 Switch func(Swift-Spritekit 项目)

swift - 由于两个存储的属性在 Swift 中不以任何方式交互,因此如何保持内存安全?

ios - 我可以从 Qt Creator 向 xcodebuild 传递参数吗?

ios - 有什么方法可以从后台跟踪当前正在运行的应用程序?

ios - Rx-Swift 干净的架构

ios - 当我在应用程序中按创建帐户时,它会在没有任何信息的情况下创建帐户

ios - 从 Realm 中分离对象?

ios - Iphone 应用程序因侵犯版权而被拒绝