UITableView content size not getting proper

3.1k Views Asked by At

I have UITableView for display for chat message list. I am using 5 type of different with dynamic height. Minimum cell height from 20 to maxHeight( approx 1000 px). UITable view cell dynamic height is set by "self.messageTableView.rowHeight = UITableViewAutomaticDimension".

  1. What Should be common estimate row height.
  2. After reload UITableView content size not getting properly. If user scroll then content size increased.
2

There are 2 best solutions below

1
kirander On

It is not enough to just set rowHeight to automatic dimension. You also need to install proper constraints for cell subviews so the cell can calculate its height based on that constraints.

0
Mansi On

To use UITableViewAutomaticDimension for dynamic height calculation, ensure

1 - Leading, Trailing, Top and Bottom constraints to cell are added correctly and not creating any conflicts

2 - Add cell.layoutIfNeeded() in cellForRowAt method of UITableViewDelegate

3 - You can give any height as estimatedRowHeight, 44 is the default value, but you can give 20(your minimum) as well.