1

I see videos where they add labels, etc. into the prototype section of a UITableViewController through the storyboard. Is this the same as if I was just adding those objects to a regular UIViewController?

I did try, but I was running into problems with constraints. If I copy and pasted an NSLayoutConstraint from a UIViewController, I would start receiving errors. So I assume constraints are handled differently also. For example, instead of using view.CenterX, it would be contentView.CenterX right?

Edit: I forgot to mention that I'm not exactly sure where the code should go. It seems like it should go into the UITableViewController, because that's where the prototype cell is, but in sample code, I see it added to the UITableViewCell.

fossdeep
  • 113
  • 1
  • 11
  • The view type of both `UIViewController` and `UITableViewController` is different, the later one has `UITableView `as its `view` property. So if your view is list-like rows, and you think everything will repeat in rows, use a `UITableViewController` and add objects to your cells. Otherwise use a `UIViewController` and build up your view. – Adil Soomro Jan 08 '16 at 22:45
  • Also, when you copy an object from a `view` having constraints relative to this `view` and then paste it to another `view`, you'll have to add constraints again (not width height constraints, but top, bottom, left, right etc) since the parent view is changed. – Adil Soomro Jan 08 '16 at 22:46

1 Answers1

0

Usually what you do is this:

  • place views and other UI components into UIViewController's root view (which is a UIView)

    or

  • place prototype static cells intoUITableViewController's root view (which is a table view)

The first case is completely flexible in terms of layout. It is your responsibility to position and size views to create a meaningful layout.

The second case is more constrained as the TableViewsimple orders all prototype cells (which themselves contain other subviews) into vertical stack.

Only you can tell what suits your needs better in context of particular project/app.

Earl Grey
  • 7,426
  • 6
  • 39
  • 59