搜索时,我想从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
    ...
}

最佳答案

要关闭搜索控制器,请使用以下方法

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

07-26 09:37
查看更多