The first screen of my application is a UITableViewController
without a navigation bar, which means that the content flows under the status bar so there's a lot of text collisions. I've adjusted both the properties for Under top bars
and Adjust scroll view insets
which do actually stop it from scrolling under, but at the cost of keeping the top of the table view under. I've attempted to set the UITableView
frame to offset by 20 pixels, but it doesn't appear to take effect and as I currently need the app to be compatible with iOS 6 I can't jump to iOS 7 Storyboards to force autolayout to use the top height guide. Has anyone found a solution that works for both versions?
Things I've tried: setting edgesForExtendedLayout
, changing the settings within Storyboard for Under top bars
and Adjust scroll view
, forcing the frame to a new area.
A picture is worth a thousand words:
For anyone interested in replicating this, simply follow these steps:
UIViewController
UITableViewController
from the Object LibraryIf you follow the above steps, when you run the app, you will see that nothing, including tweaking Xcode's checkboxes to "Extend Edges Under {Top, Bottom, Opaque} Bars" works to stop the first row from appearing under the status bar, nor can you address this programmatically.
E.g. In the above scenario, the following will have no effect:
This issue can be very frustrating, and I believe it is a bug on Apple's end, especially because it shows up in their own pre-wired
UITableViewController
from the object library.I disagree with everyone who is trying to solve this by using any form of "Magic Numbers" e.g. "use a delta of 20px". This kind of tightly coupled programming is definitely not what Apple wants us to do here.
I have discovered two solutions to this problem:
Preserving the
UITableViewController
's scene:If you would like to keep the
UITableViewController
in the storyboard, without manually placing it into another view, you can embed theUITableViewController
in aUINavigationController
(Editor > Embed In > Navigation Controller) and uncheck "Shows Navigation Bar" in the inspector. This solves the issue with no extra tweaking needed, and it also preserves yourUITableViewController
's scene in the storyboard.Using AutoLayout and embedding the
UITableView
into another view (I believe this is how Apple wants us to do this):Create an empty
UIViewController
and drag yourUITableView
in it. Then, Ctrl-drag from yourUITableView
towards the status bar. As the mouse gets to the bottom of the status bar, you will see an Autolayout bubble that says "Top Layout Guide". Release the mouse and choose "Vertical Spacing". That will tell the layout system to place it right below the status bar.I have tested both ways on an empty application and they both work. You may need to do some extra tweaking to make them work for your project.
I don't know how Kosher it is, but I found that this scheme moves the ViewController's view down and provides the status bar with a solid background:
Of course, replace
redColor
with whatever color you want for the background.You must separately do one of the swizzles to set the color of the characters/symbols in the status bar. I use
View controller-based status bar appearance = NO
andStatus bar style = Opaque black style
in the plist, to do this globally.Seems to work, and I'd be interested to hear of any bugs or issues with it.
I am using a UISplitViewController with a navigationcontroller and a tableviewcontroller. This worked for me in the master view after trying many solutions here:
It's similar to Hot Licks' solution but applies the subview to the navigationController.
I think the approach to using UITableViewController might be a little bit different from what you have done before. It has worked for me, but you might not be a fan of it. What I have done is have a view controller with a container view that points to my UItableViewController. This way I am able to use the TopLayoutGuide provided to my in storyboard. Just add the constraint to the container view and you should be taken care of for both iOS7 and iOS6.
https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TransitionGuide/SupportingEarlieriOS.html#//apple_ref/doc/uid/TP40013174-CH14-SW1