17

I updated my Xcode to 6.3 along with Swift 1.2, and I made the transition.

Everything works except dynamic row height for table view. I have those on 3 completely different table views, so it probably isn't something else influencing the bug.

I set all of the table views to:

tableView.rowHeight = UITableViewAutomaticDimension

and all of my xib files are properly constrained.

Any ideas?

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Stefan Salatic
  • 4,513
  • 3
  • 22
  • 30

2 Answers2

54

I simply added UITableViewAutomaticDimension to estimatedrowforindexpath as well. You can see how it works on the BEAM App (under 'people' category).

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewAutomaticDimension;
}
Ken
  • 572
  • 6
  • 4
  • 4
    Yes, you should provide an estimate. Additionally, according to the [docs](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UITableViewDelegate/tableView:heightForRowAtIndexPath:), there are performance implications in using the callbacks instead of the `rowHeight` and `estimatedRowHeight` properties. You could set `rowHeight` to `UITableViewAutomaticDimension`, then `estimatedRowHeight` to an arbitrary estimated value. – József Vesza May 19 '15 at 19:00
3

Estimated row height needs to be provided.

It is better not to implement estimatedHeightForRowAtIndexPath: unless necessary.

estimatedRowHeight is cheaper provided you can come up with a value

    tableView.rowHeight = UITableViewAutomaticDimension
    tableView.estimatedRowHeight = 30 //Provide any appropriate value
user1046037
  • 16,755
  • 12
  • 92
  • 138