我想在 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/