8

I'm currently updating an app to iOS8, and am replacing my own cell height calculations. I have a tableview with a bunch of custom cells. Each cell when selected will present/push a new view onto the navigationController. When the tableview is populated with these cells, and the user selects one near the bottom of the table, the tableview jumps to the top right before the new view is presented. This is very distracting to the user. I'm trying using self sizing cells introduced in iOS 8 here (in the viewDidLoad):

self.tableView.estimatedRowHeight = 60.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

Here's the code for when a cell is selected

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    UIViewController *selectedViewController = [[UIStoryboard storyboardWithName:@"Trip" bundle:nil] instantiateViewControllerWithIdentifier:@"TripDetail"];
    DetailViewController *destViewController = (id)selectedViewController;
    [destViewController setData:self.dataStore];

    [self.navigationController pushViewController:selectedViewController animated:YES];
}

Does anyone know why this is happening? And how I can make it stop?

GoshDangitBobby
  • 243
  • 1
  • 10

2 Answers2

5

It's a known issue. The tableView is calling its delegate to get an estimated height for the rows, which is causing the table to scroll.

You can wait to see if it's fixed in the next update, or implement tableView:estimatedHeightForRowAtIndexPath: (as a workaround for now) and return a cached height. Since the estimate will be the actual height, the table won't jump.

  • 1
    How to cache the height? – DarkLeafyGreen Nov 10 '14 at 08:35
  • this won't really work since its is the same with "tableView.rowHeight = UITableViewAutomaticDimension" and this is more convenient – eNeF Jan 21 '15 at 03:42
  • @nfer Even though the height has been determined, the bug makes it revert to the estimated height instead of the actual height. So, by having the estimate return the actual height, as a workaround for now, it stops the table from jumping. Because of the nature of the issue, it actually does work, even though it's not really logical. –  Jan 21 '15 at 03:51
  • This does indeed work. Tis' a shame this bug exists (even in iOS 8.4). Self-sizing my butt – mattsven Aug 08 '15 at 21:56
1

This happen's when the table delegate was tapped "didSelectRowAtIndexPath:" because the delegate method "numbersOfSectionsInTableView" && "numbersOfRowsInSection" will get called. its like reloading the table.

You can fix that jumping state with this method "heightForRowAtIndexPath:" however you'll have to disregard your auto sizing.

eNeF
  • 3,241
  • 2
  • 18
  • 41