For many, many hours, I struggled to get a dynamic calculation of the row height to run UITableViewCells.
A StackView (attached to the content fields of a UITableViewCells contentView) should allow me to control the height of the cell by manipulating the hidden property of the views inside the StackView (as shown here: https://stackoverflow.com/a/313809/ ... )
I added the required settings for dynamic height in the viewContoller as follows:
self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 44;
I did not redefine heightForRowAtIndexPath since I want auto layout to do magic.
My problem is that while the tableView is loading first or scrolling through the table is being viewed, the cells are not being captured correctly. But when I click inside the cell, the height calculation really works, and all the cells are displayed at their correct height.
I redefined setSelected from a UITableViewCell as follows:
-(void)setSelected:(BOOL)selected animated:(BOOL)animated{ [UIView setAnimationsEnabled:NO]; [super setSelected:selected animated:animated]; self.viewInsideStackView.hidden = !selected; [UIView setAnimationsEnabled:YES]; }
This gets a call in the form of table loads or scrolling for each cell. Manipulating self.viewInsideStackView.hidden should make the stack view recount its height. But that does not work. I also tried calling layoutIfRequired , but still the wrong size appears until I click on the cell.
Jakob source share