Brian Sachetta
Brian Sachetta

Reputation: 3463

iOS UITableViewAutomaticDimension RowHeight Poor Performance / Jumping

I'm building a basic table view on iOS 8. I watched the WWDC '14 video on the topic of autosizing cells and am trying to reproduce the concept, but am having some issues. On viewDidLoad: I am calling:

//estimate for my cells though they may vary

self.tableView.estimatedRowHeight = 300.0;

self.tableView.rowHeight = UITableViewAutomaticDimension;

When my view and table load up, performance is ok. When I click on a cell, the program takes me to a detail view. When I hit the back button on that view and return to the table view, that's when things start acting weird. The cells then start 'jumping' while I am scrolling. By jumping I mean that they don't scroll smoothly - they tend to jerk or jump from one place to the next.

I should add that memory is not a concern since the cells are being reused and there is little data in the background. The constraints on my cells (in storyboard file) are also blue and I am seeing no autolayout constraint exceptions in the debugger.

Has anyone else seen this kind of behavior with UITableViewAutomaticDimension? Is it just an Apple bug or is there more to it? Thanks.

Upvotes: 6

Views: 5023

Answers (3)

umakanta
umakanta

Reputation: 1059

In cellForRowAtIndexPath add below line

cell.textLabel.numberOfLines = 0;

Upvotes: 0

I have found weird issue using the line self.tableView.rowHeight = UITableViewAutomaticDimension;

But then, everything came a lot better when I replaced it with the delegates method. In your case would be :

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

- (CGFloat) tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 300.0f;
}

Upvotes: 6

Yogesh More
Yogesh More

Reputation: 239

ADD one more delegate method to the code

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{ return Approxheight;}

it will load uitableView early than current time. i hope this will work for you.

Upvotes: 0

Related Questions