ios - 如何隐藏下一屏的过渡searchBar

标签 ios swift

添加了搜索栏TableView,但是当正在查找的项目之一并过渡到其页面时,搜索栏和模块键入不会被删除并保留在屏幕上。我们如何过渡到搜索栏模块输入清理?

enter image description here

最佳答案

如果您使用过UISearchController,请将viewWillDisappear:放入viewController中。

//this is my searchController, created programatically
var searchController : UISearchController?;

override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated);

        if let sc = self.searchController where sc.active {
            self.searchController?.dismissViewControllerAnimated(false, completion: nil);
        }
    }

原因: UISearchControllerUIViewController 的子类。 如果您的搜索栏处于事件状态,则意味着它位于您当前的 viewController 之上。因此,在退出 viewController 之前,您需要使用其属性 .active 检查它是否处于 active 状态。

关于ios - 如何隐藏下一屏的过渡searchBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35127593/

相关文章:

ios - 为 Xcode 安装 OpenSSL 库

ios - Xcode 无法启动应用程序,因为设备已锁定

ios - setContentOffset 从 ScrollView 的底部开始不起作用

ios - Apple Healthkit 和 Watch 模拟器

Swift - 在类中引用类的类型

ios - 从元数据中提取图像图片样式

ios - 将目标添加到 Collection View Nib 内的按钮操作

ios - 尝试从外部模态视图 Controller 调用 View Controller 函数时出现 fatal error

html - 如何在 UIWebView 中水平和垂直居中 HTML 字符串

ios - 遍历 SKNode 的所有子节点?