I added a searchBar into a tableview. I also have a navigationbar and it should appear under it. It works fine until I tap into the searchbar. When I do so on devices with larger screen size (from iPhone 6) the searchbar hides under the navigationbar. It works as expected on an actual iPhone 5, 5s. This is how I initialize the searchBar:
searchController.searchResultsUpdater = self as UISearchResultsUpdating
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.tintColor = UIColor.black
searchController.searchBar.scopeButtonTitles = ["Device", "Person", "OS version"]
searchController.searchBar.delegate = self as UISearchBarDelegate
The searchBar should not hide because I need the segmented control on the navigationBar when I'm searching too. Do you have any idea how can I fix this problem?
Update: After setting the extended edges the searchBar looks like this:
I solved the problem. It was an iOS 11 issue. According to wwdc recommendation you should add the searchBar for the navigationItem.
if #available(iOS 11.0, *) {
self.navigationItem.searchController = self.searchController
self.navigationItem.hidesSearchBarWhenScrolling = false
} else {
tableView.tableHeaderView = searchController.searchBar
}
This solves the problem and it's working fine with any iOS type now. The searchBar will look like this on iOS 11:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.