ios - 在 Swift 2.x 和 iOS9 中以编程方式关闭 searchBar

标签 ios swift tableview uisearchbar searchbar

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

已关闭 7 年前

我使用 searchBar 作为 tableView 的过滤器。 我读过几篇文章,包括

self.definesPresentationContext = true

关闭 searchBar,但这不是我的情况。 我想要实现的是,一旦用户点击该栏,如果不满足某些条件,它就会取消搜索并关闭它。

我也尝试过

searchController.active = false

没有结果。任何人都可以帮忙吗?谢谢

最佳答案

尝试:

[searchController.searchBar setHidden:YES];

您可能还想关闭 presentingViewController。

虽然正如马特指出的那样,这是一种奇怪的做法。如果不满足条件,您最好显示一个 alertView,甚至不显示 searchBar。

关于ios - 在 Swift 2.x 和 iOS9 中以编程方式关闭 searchBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37420974/

上一篇:android - 摄像头人脸检测

下一篇:ios - 我的应用程序未显示在定位服务下(设置->隐私)

相关文章:

ios - TableView 单元格中的 UITextField 显示问题

ios - 在搜索栏中输入第一个字符后应用卡住

ios - CGAffineTransformMakeScale 的隐式声明无效

swift - TableView 没有使用正确的 TableViewCell

swift - 如何为 swift 字典实现观察者模式

ios - 使用 +1000 值转换日期

ios - 单击TableViewCell时如何将数据从NSObject传递到另一个ViewController?

ios - 复合主键域/swift

ios - AudioKit 如何更新绘图以更改颜色或原型(prototype)

ios - 如何使用 iPod Touch(第 4 代)获取 gps 位置