我正在尝试在我的 tableViewController 中使用新的 UISearchController。
但是,当我像使用旧的 searchDisplayController 那样按下 searchBar 时,它如何在 navigationController 中向上移动,我有点困惑?
目前它只是停留在表头中。
这是我的代码:
self.teamSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchBar.searchBarStyle = UISearchBarStyle.Minimal
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.showsScopeBar = true
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
Controller :
当我点击搜索栏时:
最佳答案
可以将UISearchController
的UISearchBar
放在导航栏中,而不是放在表头
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;
self.definesPresentationContext = YES;
关于ios - 导航栏中的 UISearchController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29922691/