当segue到另一个视图时隐藏UISearchController

时间:2016-05-19 02:20:08

标签: ios swift interface-builder uisearchcontroller

当我想要时,我想从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
    ...
}

3 个答案:

答案 0 :(得分:2)

解除方法

下面的搜索控制器使用
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
  searchController.active = NO;
}

答案 1 :(得分:0)

div { border: 1px solid #f0f; height: 50px; box-sizing: border-box; width: 400px; } #LeftContent, #RightContent { float: left; } #CentredDiv { width: 800px; clear: left; } 中,您可以为此添加下一行

viewDidLoad()

答案 2 :(得分:0)

最后,为我做了什么(Swift 4):

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
         print("prepare for segue")
         searchController.isActive = false
    }

definesPresentationContext 中的方法viewDidLoad()对我来说不起作用

    definesPresentationContext = true

也不:

    searchController.definesPresentationContext = true

也不:

    self.definesPresentationContext = true
相关问题