0

I have a navigation controller with a UITabBarController as the initial view controller. Within that, I have two UIViewController's as sub-viewcontrollers in the tab bar controller. Both of my view controllers have UITableView's in them. The first one always looks fine. However, the second view controller always has a messed up content inset. I don't know why because there doesn't seem to be any difference in the way I setup my table views. I can manually set the content inset in viewDidLoad, but there's got to be a better way since it's working by default in the first view controller.

This is the first table view. As you can see, the the content offset looks fine.

Something to note: when opaque navigation bars are turned off, the issue goes away.

enter image description here

This is the second table view. As you can see there is a table view cell underneath the navigation bar.

Second TableView

Homeschooldev
  • 405
  • 1
  • 7
  • 18
  • Have you tried setting the extended edges property on your view controllers? That seems to work the best for me with regards to handling the navigation and tab bars. I'm sure there is some IB flags that can be used to do the same, but the fact that Autolayout doesn't fix itself has convinced me to do this kind of thing in code. – Andrew Monshizadeh Sep 19 '14 at 01:36
  • Are you manually setting the contentInset? UIViewController has automaticallyAdjustsScrollViewInsets which could mess things up when you try to manually set the insets. Either set automaticallyAdjustsScrollViewInsets to NO and set the insets yourself or let your view controller do the work by setting automaticallyAdjustsScrollViewInsets to YES. – JonasG Sep 19 '14 at 01:38
  • automaticallyAdjustsScrollViewInsets is set to YES automatically. It's set on both view controllers. The thing is I don't want to worry about setting it manually because the navigation bar height changes and the status bar hides when in landscape. There's lots of different variables. I was hoping I was just missing something, but this might be a bug. – Homeschooldev Sep 19 '14 at 02:35
  • As far as I know, the automaticallyAdjustsScrollViewInsets only adjusts content insets of the first child view (if it's a ScrollView) found in the VC's child views. So if you have some other element as the first child in the child views, then the inset isn't adjusted automatically. – lekksi Oct 02 '14 at 10:03
  • iOS8 also introduced layoutMargins property for UIView, which can also affect the layout. This might be helpful: http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working/25877725#25877725 – lekksi Oct 02 '14 at 10:05

1 Answers1

0

I fixed the issue by changing the structure of my view hierarchy. Apparently I should not of had a UINavigationController as the initial view controller, but rather had the UITabBarController as the initial view controller and from there have UINavigationControllers within the tab bar where needed.

Homeschooldev
  • 405
  • 1
  • 7
  • 18