I have a UISearchController
with a UITableViewController
as a searchResultsController
, the UISearchBar
of this sear
Have you tried to set the hidesNavigationBarDuringPresentation to false? Solved my headache..
self.searchController.hidesNavigationBarDuringPresentation = false;
Putting the searchbar in the navigation bar gives a more solid user experience in my opinion (for iphone)
self.navigationItem.titleView = self.searchController.searchBar;
SWIFT 3.01
func willPresentSearchController(searchController: UISearchController){
self.navigationController?.navigationBar.isTranslucent = true
}
func willDismissSearchController(searchController: UISearchController) {
self.navigationController?.navigationBar.isTranslucent = false
}
Try this out:
First you need to delegate the
UISearchControllerDelegate
For Swift
func willPresentSearchController(searchController: UISearchController) {
self.navigationController?.navigationBar.translucent = true
}
func willDismissSearchController(searchController: UISearchController) {
self.navigationController?.navigationBar.translucent = false
}
To make this clearer @Lorenzo's answer worked for me.
self.definesPresentationContext = YES;
In Swift, try:
override func viewDidLoad() {
edgesForExtendedLayout = []
searchController.hidesNavigationBarDuringPresentation = false
// ...
}
In my case the searchBar was in the tableHeaderView and there was no NavigationBar on screen. But the SearchBar still animated upwards overlapping the status bar when becoming active. The solution to prevent this was to set:
searchController.hidesNavigationBarDuringPresentation = false
Which is weird because as I said the view controller was not using a navigation bar.