Table View Controller and Navigation Bar

This is driving me absolutely mad and should be simple. In fact I'm sure it IS simple and it's just that I don't understand why not!


I've got a very basic navigation-bar app. Trivial in fact. A table view embedded in a navigation controller. Instead of the UIViewController to show the detail (as per the template example) I want a UITableViewController so I've ditched the UIViewController, added the UITableViewController and created the necessary segue.


However I cannot find how to ensure the top constraints are correct - the table covers the navigation bar. I've literally tried everything over the past 3 hours and nothing works.


Surely this is THE most basic scenario that should just work, so why isn't it?


How do I get the detail table view to have room at the top for the navigation bar?

Normally when you tick "Adjust Scroll View Insets", and Extend Edges "Under Top Bars", in the view controller's attributes inspector in the storyboard, it should work. The view will extend to the screen edge, but UIKit should adjust the contentInset (and scrollIndicatorInsets) to account for the navigation bar.


If you have been playing fast and loose with UIViewController types in the storyboard, that sometimes messes things up. By that I mean you can't drag out a UIViewController then change its class to UITableViewController in the Identity Inspector (or vice versa). You have to drag out a VC of the appropriate type in the first place.


Have you overridden any layout-related methods in your VC class? Are you calling super?

Yes 'Adjust Scroll View Insets' and 'Extend Edges Under Top Bars' are ticked and this was a completely new UITableViewController dragged into place. The overriden layout-related methods are the standard ie viewDidLoad and all it does is call super.


The key point I would add is that it looks wrong in Xcode let alone when you run it, so something about the drag-drop into the storyboard just isn't right.

Accepted Answer

OK the answer to this seems to be embedding the second view controller in another navigation controller using Editor->Embed In->Navigation Controller after creating the initial segue directly to that view controller. That now looks fine in IB and runs fine.


Not entirely happy this is the answer as the template app doesn't use this approach so would still welcome any comments.

Table View Controller and Navigation Bar
 
 
Q