Search code examples
iosautolayoutuicontainerview

How to layout with two container views with embedded tables


I am trying to layout the following UI View

The Main UI View has two Container Views. The top container view embeds a static table controller. The bottom container view embeds another table controller which I want to be dynamic.

How can I set the layout so that the height of the top container view is equal to that of the top table, and the bottom container view gets the rest?

Right now height is ambiguous for the container views.


Solution

  • Constraint your top table view's height to some fixed value (it doesn't matter what).

    Make an outlet of that height constraint.

    In your view controller, do this:

    heightConstraint.constant = tableView.contentSize.height
    

    this way bottom view will adjust accordingly.

    Make sure to disable bouncing in the top table view.