I have a tableview UITableViewAutomaticDimension
for auto layout, and I get the tableview content size to make the tableview height as it content height after tableview cell configure and reload, this height isn't right it seems calculate by estimatedRowHeight
. I know I can get the last right height use kvo to observe the tableview content size, but I don't know which is the last right one, because I just want do something once when content size is right. How can I do that?
Asked
Active
Viewed 378 times
2

Wayn Liu
- 394
- 3
- 13
-
Insufficient information. On one hand UITableViewAutomaticDimension and estimatedRowHeight are necessary for dynamic cell layout but on the other hand it also depends on how you have laid out the cell constraints. – Saroj Oct 13 '15 at 04:47
-
Are you manually setting the content size of the table? Using automatic dimension you don't need to specify anything but correct constraints from top to bottom. – krishnanunni Oct 16 '15 at 11:06
1 Answers
2
you need to add a delegate method like
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{return UITableViewAutomaticDimension;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
before that you should pin 4 sides on that contents which you dropped in prototype cell.
now you got the exact row heights of each cells.

Thanveer Ahammed
- 148
- 9