sonxurxo
sonxurxo

Reputation: 5718

Nested UITableViews with autolayout

I've got a layout with nested UITableViews (each UITableViewCell's contentView has as unique child another UITableView).

All the leaf cells are correctly set up with autolayout (in fact, when they are presented in a single table they are displayed ok).

But when they are inside the inner table, the outer table does not calculate the correct heights for cells, leading to their standard height of 44. I'm using

self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 260;

for both inner and outer tables.

How can I get the tables to show correct heights with autolayout? (I don't want to override tableView:cellForRowAtIndexPath:, I want autolayout to do the trick).

Thank you in advance

Upvotes: 0

Views: 381

Answers (1)

Andrea
Andrea

Reputation: 26385

I personally think that nesting tableview is a bad UX experience. Better you'll find a different approach for your users.
Saying that they also lead to different problems, for instance who scroll first etc. In your case the issue is due to the fact that UITableViewAutomaticDimension simply send to the cell content view -systemLayoutSizeFittingSize(or similar) with UILayoutFittingCompressedSize, that for a scroll view means 0;0 basically your table view is not counted while calculating the cell height.
In my opinion now you have 2 options:

  • make your calculus manually and cache the result for a faster scrolling
  • create a subclass of a UITableView that when asked for its intrinsicContentSize returns a custom size

Really hope this helps.

Upvotes: 1

Related Questions