ios - 切换到另一个 View 时隐藏 UISearchController

标签 ios swift interface-builder uisearchcontroller

我想在 segue 时从 tableHeaderView 中隐藏我的搜索栏。我怎样才能做到这一点?我按如下方式创建搜索栏:

override func viewDidLoad() {
   ...
   resultSearchController = ({
        let searchController = UISearchController(searchResultsController: nil)       //  The results of the search will be presented in the current Table View, so the searchResultsController parameter of the UISearchController init method is set to nil.

        searchController.delegate = self        
        searchController.searchBar.delegate = self          // Without this selectedScopeButtonIndexDidChange won't get called.
        searchController.searchResultsUpdater = self
        searchController.hidesNavigationBarDuringPresentation = true    // NOTE: if false and tapping on a reminder to go the its details and then back then the titles may be screwed up.
        searchController.dimsBackgroundDuringPresentation = false       // NOTE: If true it would result in the filtered list not being scrollable.
        searchController.hidesBottomBarWhenPushed = true
        searchController.searchBar.sizeToFit()
        self.definesPresentationContext = false    

        searchController.searchBar.scopeButtonTitles = SCOPEBAR_OPTIONS.descriptionArray
        tableView.tableHeaderView = searchController.searchBar
        return searchController
    })()

我试着像这样简单地将它设置为 nil,但没有成功:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    tableView.tableHeaderView = nil
    ...
}

最佳答案

要关闭搜索 Controller ,请使用以下方法

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
  searchController.active = NO;
}

关于ios - 切换到另一个 View 时隐藏 UISearchController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37312906/

相关文章:

objective-c - 身份标签的值可以在代码中访问吗?

ios - 显示/隐藏容器 View 时控制 View Controller 的生命周期

ios - 如何在iphone sdk中播放原始pcm数据

快速用户界面 | VStack 不会在 ForEach 循环内部工作

swift - MFMailComposeViewController 不工作- swift

ios - 如何修复 Firebase SIGABRT 崩溃 iOS

interface-builder - Xcode Interface Builder 9.1 Collection View Cells 太小 "expected height"

cocoa - Mac应用程序: Auto-Resizing of subview doesn't work

ios - 内部测试器单选按钮未在 iTunes Connect 中显示

objective-c - 如何在 Objective-C 中将变量添加到类别?