9
votes

I am using Xcode 5 with storyboard and auto layout. My views are:

  • root navigation view
  • tab view controller (its the default view for the navigation view)
  • two tab views

In both tab views, I put a UITableView on it, and I set up the standard IB stuff. Both tab view controllers are nearly identical in code in terms of setup (they both derive from UIViewController).

For the tableview however, things are weird. The first table view has the right setting, where the cells start "below the navigation" and you can scroll it up. The second table view starts with the cells "under the navigation" - it seems like the insets are wrong.

But why would it be wrong for just the second tab view, and not the first? I did not do anything funky with either, and I've pored over the code multiple times to be sure that both tableview controllers are nearly identical (except in the cell contents).

(on the second image, notice the bit of green under the "Carrier" status bar).

First tab view - looks right

Second tab view - looks wrong

12

12 Answers

20
votes

I faced this same problem once.

Try toggling the "Under Top Bars" in the view controller's Attributes inspector.

This worked for me. Hope it does for you too. Thanks.

4
votes

Trying toggling the "Adjust Scroll View Insets" in the view controller's Attributes inspector. You want it ticked.

enter image description here

4
votes

Sadly it seems that if you have the TabBarController as the RootViewController for the NavigationController ( Navigation -> Tab -> Table View C, Table View C ) this will happen. The fix may be to give each table view their own navigation controller ( Tab -> (Nav -> Table View C), (Nav -> Table View C) While that may not work with all desired designs, it worked in my situation (which was the same as yours)

3
votes

After some investigation I found the issue. The problem was that my tab bar controller was not the root, but the nav controller was. Once I made the tab bar controller the root, and put the Navs in the different tabs, everything was fixed.

How to eliminate "two-stage rotation" warning?

2
votes

One of the replies here helped and worked:How do I make my iOS7 UITableViewController NOT appear under the top status bar?

In case anyone is still reading this thread:

What worked for me is to also uncheck the "Extend Edges" options in the parent tab bar controller. That gives a consistent behaviour in iOS7 as well as iOS6.

2
votes

Old question but I wanted to tell how I solved my issue after many solutions I have tried that didn't work.

I have solved it by calling edgesForExtendedLayout so it wont go behind the navigation.

self.edgesForExtendedLayout = UIRectEdge.None
1
votes

What worked me this time was to uncheck on Extend Edges "Under Top Bars" on the ViewController attribute inspector.

enter image description here

1
votes

In my case my structure is NavVC -> Tabbbar -> Tabs VCs. I had views in tabs VC 20px pushed down. I tried all these answers but didn't work. what worked for me is Tabbbar -> Under Top Bars -> unchecked. left NavVC and TabsVCs untouched.

1
votes

Adding the following in viewDidLoad worked for me

self.edgesForExtendedLayout = []
1
votes

If all else fails.
tableview.contentInset = UIEdgeInsetsMake(28, 0, 0, 0)

0
votes

I found a solution with tabs. Add this in viewDidAppear

let topOffest = CGPointMake(0, -(self.tableView.contentInset.top))
self.tableView.contentOffset = topOffest
0
votes

As per my understanding, storyboard doesn't allow embedding tab bar controller inside navigation controller, so it look like it is not recommended design by apple. However, in one of my application I used this design and it stared causing issues with iOS 11 with introduction of safe area.

As a fix, I unchecked the "Under Top Bars" property of view controller where I was facing the issue.