ios - UISearchController 禁用取消按钮

标签 ios swift uinavigationcontroller uinavigationbar uisearchcontroller

<分区>

我正在设置一个 UISearchController嵌入 UNavigationBar无论我尝试什么,我似乎都无法禁用尝试在 UISearchController 中键入内容时出现的“取消”按钮searchBar . 所以我的问题是你是怎么做到的? 到目前为止,我已经尝试了以下方法,但都没有用。

searchController.searchBar.showsCancelButton = false 

searchController.searchBar.setShowsCancelButton(false, animated: false)

最佳答案

您可以通过 UISearchBar 委托(delegate)方法禁用取消按钮。

func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
    searchBar.setShowsCancelButton(false, animated: false)
}

func searchBarTextDidEndEditing(searchBar: UISearchBar) {
    searchBar.setShowsCancelButton(false, animated: false)
}

关于ios - UISearchController 禁用取消按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48412296/

相关文章:

ios - 调用 PFUser.logOut() 解析后,当前用户不为零,swift2

ios - TableViewCell 中的 UIButton 调用 2 个函数

objective-c - 无法指定存储类(Objective-c)错误

ios - Swift:我无法使自动布局约束适用于我的 UIScrollView

objective-c - 委托(delegate)方法 'canMoveRowAtIndexPath' 的目的是什么?

ios - 导航标题未显示在带有选项卡 View Controller 的 View 上,但 "back"导航有效

xcode - TabBar嵌入导航 Controller ,后退按钮不会消失

ios - 如何解决链接器命令错误?

ios - 插入行后 UITableViewCell 动态高度中断

iPhone SDK : UIBarButtonItem not refreshing after Memory warning