Search code examples
xcodeios6autolayout

Autolayout with TableViewController


I have my DetailViewController that I originally based on a UIViewController. The view uses Table View with static cells, but xcode then started to complain that I should use UITableViewController as a base class for the view. So I changed my view to be subclass of UITableViewController and wired everything again. There is a Date Picker in the bottom and when I start to use Autolayout to set constrains, xcode does not allow me to manage these under TVC. My setup works fine under ViewController.

Are there any limitations with Autolayout under TableViewController? I can also see that Table View always fills up whole view under TVC and does not allow uder subviews to exist on the same level.

Many thanks!


Solution

  • Only the UITableViewController can use static cells defined in the storyboard. However, it can only really show a table view, not other views as well - it's view property is the table view, which you can't just add new subviews to.

    The solution is to use a table view controller to hold and manage the table, and to make this a child view controller of your main controller. This is trivial to achieve in storyboards using a container view and embed . The table view is then a subview of your main view controller's view, and you can add additional views such as the picker just as you were before.