UITableView content overlaps Status Bar when UISearchBar is active

Kenny Wyland picture Kenny Wyland · Apr 17, 2014 · Viewed 13.5k times · Source

I have a UITableViewController with a UISearchBar and UISearchDisplayController. That exists inside a Container View in a UIViewController which is in a UINavigationController. I made this image to help describe the structure:

enter image description here

This is what it really looks like:

enter image description here

When I tap the Search Bar, I have to hide the Nav Bar. Normally, this would happen on its own, but since my UITableViewController is inside a Container View, I have to handle that change myself. This is what it looks like then, note that the Status Bar is white because the Nav Bar is white, even though it is Hidden at the moment.

enter image description here

Once I start typing in some search text, the results show up. If I scroll those results upward, they pass underneath the Search Bar, but they overlap the Status bar which is very unattractive.

enter image description here

If the Container View isn't involved, then this all works as intended and the table content passes underneath the Status Bar, but with the ContainerView involved, the table text and status bar collide.

How do I get the text to travel under the Status Bar like normal?

Answer

nonolays picture nonolays · Jul 10, 2015

I have search this for hours and my final result was to put this line in viewDidLoad: self.extendedLayoutIncludesOpaqueBars = YES;

Problem solved :)