Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

UITableViewController Overlaps Statusbar

Hi,

I am currently going through the iOS track and I am on the building a blog post reader. When recreating the project and implementing a UITableViewController from scratch the table and its contents are within the space of the status bar and as such looks quite odd.

Please see a screen shot here

If someone could tell me how to use the storyboard editor (if possible) to make the table view give enough space for the status bar that would be great!

Thanks,

9 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

If you write something like this in you viewController's viewDidLoad:

self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];

Thanks, but why is that happening if I may ask (just so I can get my head around it).

Thomas Nilsen
Thomas Nilsen
14,957 Points

The exact explanation I'm not sure of to be honest. I'll tag Amit Bijlani . He should be able to provide a good answer. Also, you wouldn't have to write the line I gave you if you embed the viewController in a UINavigationController

Ah, ok ill bear that in mind in the future - possibly will change it when im done with these videos. Thanks for your help!

Gareth Borcherds
Gareth Borcherds
9,372 Points

So from what I read on the issue, this is something that was introduced in the redesign of the iOS items and is something unique to iOS 7. With the new flat design they allowed for content to scroll under the status bar and in some cases the nav bar. From what I understand though you should be able to fix this by navigating to the attributes inspector and under view controller, you'll see some settings for extend edges, unclicking the boxes resolved the issue for me.

Thanks Gareth, I have just unchecked the 'Under Top Bars' for extend edges however it still seems to overlap. What Thomas provided seems to work although I would rather do it on the storyboard if possible.

Gareth Borcherds
Gareth Borcherds
9,372 Points

Yeah, I was reading some more on this and it seems to be an issue a lot of people are dealing with. I couldn't find anything good on how to solve it with the table views.

I'd be interested in any kind of solution, but it looks like Thomas' suggestion above is the best way to deal with it without embedding it in a navigation controller or putting one in on that view. I wonder if Apple just assumes you won't be using a table without a navigation bar? Seems kind of weird.

Also, I looked more into the Under Top Bars and it seems that is more related to scroll views and applies mainly to navigation bars as to when you would use it the most, it apparently doesn't work in this scenario.

Thanks for that Gareth, I suppose in an working app you would most probably have navigation where there is a table view controller as that would seem perfectly logical.

Patrick Serrano
Patrick Serrano
13,834 Points

You could always make the tableview 20pts shorter and then set the y value to 20 which would push the tableview down below the status bar instead of making it the full height of the screen.