0

I have a tableView which rows' heights are calculated dynamically using UITableViewAutomaticDimension and AutoLayout constraints from IB.

I have a label inside each cell bound to a ReactiveCocoa MutableProperty, so that it gets updated whenever that changes.

Text changes also often outgrow the existing cell and I can't seem to find a way to notify the UITableView that the height of the cell should be recalculated.

enter image description here

Using tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) or tableView.reloadData() is not an option, since it is far to invasive and can result in loops unless explicitly managed...

Is there any way to just convey the minimal information "please update the height of this UITableViewCell", without discarding the cell?

cell.setNeedsLayout() does not seem to suffice.

Timm
  • 2,652
  • 2
  • 25
  • 34

1 Answers1

3

According to this answer, the only way to reliably resize a UITableViewCell after it's been added to the table view, and the method suggested by Apple, is to call the following two methods:

[tableView beginUpdates];
[tableView endUpdates];
Community
  • 1
  • 1
rpowell
  • 1,464
  • 2
  • 16
  • 29
  • Well, this is not ideal, as I can't call it in `cellForRowAtIndexPath` since that crashes the app (understandably, maybe). So I still have to use a flag like `isInitialTextChange` and then skip the update on that. But now at least it works and does not crash. – Timm May 19 '15 at 09:22