1

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.

rrevo
  • 1,647
  • 1
  • 16
  • 22
  • By "height of the top table", you mean the minimum height so that all the cells can be displayed without scrolling? – Nicolas Miari Sep 22 '17 at 06:57
  • I think you should add a height constraint to the top container view, and an outlet to it in code. Then, at runtime, the table's **content size** and adjust the cosntraint's `constant`. https://stackoverflow.com/a/17939938/433373 – Nicolas Miari Sep 22 '17 at 07:00
  • The top table has 3 rows so I want that to be shown. The bottom table might have many more rows.. so that should scroll (it that makes sense) – rrevo Sep 22 '17 at 07:01

1 Answers1

0

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.

Nicolas Miari
  • 16,006
  • 8
  • 81
  • 189
rv7284
  • 1,092
  • 9
  • 25
  • This. Just make sure you query the table's `contentSize` at the **right moment** (see the answer linked in my previous comment for that). – Nicolas Miari Sep 22 '17 at 07:04
  • @NicolasMiari I was able to follow the other instructions except when to query the contentSize. – rrevo Sep 22 '17 at 07:24
  • @rrevo the answer I linked deals with how to force the table view to update its content size, so that the queried value is valid. Check it out. – Nicolas Miari Sep 22 '17 at 07:27