Search code examples
swiftuisearchcontrolleruisplitview

searchBar from UISearchController not showing correctly on split view on iPad


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).

enter image description here

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.

enter image description here

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.

enter image description here

Addendum: I just found out that on iPhone things aren't perfect either: it shows the searchBar on the detailView :

enter image description here

(And this is both with or without the navigation controller showing)

grrr I'm tempted to go back to the good old UISearchDisplayController


Solution

  • After much googling found out that adding this line of code in my ViewDidLoad of my TableViewController fixed the problem :

    self.definesPresentationContext = true