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

Stanley Gao
Stanley Gao
3,889 Points

View keeps extending full screen and stacking over status bar. How can I fix it?

I created a Table View Controller and it blocks the status bar. I can't find a way to resize the table view. I have googled this problem and the answers are not helpful.

I tried to check all three boxes under Attribute Inspector -> View Controller -> Extend Edges "Under Top Bars, Under Bottom Bars, and Under Opaque Bars". It didn't have any effect.

I also tried to do it programmatically in viewDidLoad function using:

```Objective C self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0);

This did move the section bars below the status bar. However, when I swipe down, the rows are still showing up in status bar.

I have been stuck here for days, can anyone show me how to fix it please.

1 Answer

Stone Preston
Stone Preston
42,016 Points

below is a quick and easy fix.

you can add an empty tableHeaderView to your table that is the same height as the status bar and it will push it down below the status bar:

place the following code in viewDidLoad:

UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
self.tableView.tableHeaderView = headerView;
Stanley Gao
Stanley Gao
3,889 Points

Thank you for your response. I have tried this code and it has a problem. It pushes down below status bar initially, but when I scroll down the top would be pushed up to status bar again.

Stone Preston
Stone Preston
42,016 Points

make sure the extend edges for top bars, bottom bars, and opaque is UNCHECKED. extending the edges under those means that the view goes beneath it (what you dont want)

Stanley Gao
Stanley Gao
3,889 Points

I did uncheck them, it still does the same thing. It might not be that reason.

I also noticed when I click the "table view" in Table View Controller Scene, the highlight on my storyboard actually covers the status bar. I think the the default size of the view is overextended but I can't find a way to resize the table view.

Stone Preston
Stone Preston
42,016 Points

try cleaning your build (command + k) . sometimes storyboard changes dont go through until you do a clean.

the code I posted above should definitely work, and im not sure why it would not work when you swipe up. make sure you remove the inset code you said you tried.