ios - 如何在 ui 搜索栏中的 x 按钮操作事件上 resignfirstResponder?

标签 ios iphone xcode swift uisearchbar

我无法检测 UISearchBar iOS 9 中的 x 按钮操作。有人可以帮助我吗?

最佳答案

如果您的 View Controller 是您的搜索栏委托(delegate),您可以从那里实现 searchBarCancelButtonClicked 函数和 resignFirstResponder

func searchBarCancelButtonClicked(searchBar: UISearchBar) {
    searchBar.text = ""
    searchBar.resignFirstResponder()
    // or you could force view to end editing mode using self.view.endEditing(true)
}

关于ios - 如何在 ui 搜索栏中的 x 按钮操作事件上 resignfirstResponder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37132015/

相关文章:

swift - presentController(withNames :contexts:) is executed) 时如何显示数组的第二个屏幕

ios - 字体 BebasNeue 不适用于 iOS 11

ios - UIWindow addSubview 在 iOS 9 中不起作用

objective-c - 从 iOS 而非 FbAppName 发送的 Facebook native 共享对话框?

ios - AGSLocalTiledLayer 未使用 .tpk 文件加载 map

ios - 如何使用选择器方法传递多个参数

iphone - 相机图像改变方向

objective-c - 将文本放置在 UIView 上的自定义位置

ios - 如何在后台接收 iOS 上的 watchOS 文件传输

iphone - 按下声音按钮时,AVAudioPlayer会提供惰性反馈