问题
Today I migrated my code from UISearchDisplayController (deprecated in iOS 8) to UISearchController and the search bar now is not always showing correctly.
I'm using a UISplitViewController that is ALWAYS showing the master column (so also on an iPad/iPhone6+ in portrait).
I prefer this visually over the user having to swipe from left to right to see that column.
If open the application an tap on an item in the master column, the detail column loads and the searchBar is resized appropriately.
However if I open te application en enter something in the searchBar, then tap on one of the results the detail also loads correctly but the searchBar is NOT resized.
Addendum: I just found out that on iPhone things aren't perfect either: it shows the searchBar on the detailView :
(And this is both with or without the navigation controller showing)
grrr I'm tempted to go back to the good old UISearchDisplayController
回答1:
After much googling found out that adding this line of code in my ViewDidLoad of my TableViewController fixed the problem :
self.definesPresentationContext = true
来源:https://stackoverflow.com/questions/32171704/searchbar-from-uisearchcontroller-not-showing-correctly-on-split-view-on-ipad