Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewAutomaticDimension not working in Xcode 6.3

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?

like image 882
Stefan Salatic Avatar asked Apr 10 '15 15:04

Stefan Salatic


2 Answers

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;
}
like image 88
Ken Avatar answered Nov 10 '22 10:11

Ken


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
like image 45
user1046037 Avatar answered Nov 10 '22 11:11

user1046037