UITableViewAutomaticDimension not working in Xcode 6.3
Asked Answered
A

2

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?

Americanist answered 10/4, 2015 at 15:20 Comment(1)
Did you add an estimatedRowHeight? without that it will not workGeneralissimo
L
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;
}
Landscapist answered 10/4, 2015 at 17:2 Comment(1)
Yes, you should provide an estimate. Additionally, according to the docs, 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.Divertimento
V
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
Variscite answered 27/6, 2016 at 12:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.