9

I am reloading some cells in my table view. After the reload is done, I want to scroll so that they are visible. I am aware of the scrollToRowAtIndexPath:atScrollPosition: method. But I need to call it after the reload as done, as said reload will change row heights.

Here are some related questions, but they don't quite answer my question.
UITableView , Scroll to bottom on reload?
How to Start UITableView on the Last Cell

EDIT -- My reload does not insert or delete any rows. Rather, I am reloading one or more cells to reflect updated information.

Community
  • 1
  • 1
William Jockusch
  • 26,513
  • 49
  • 182
  • 323

2 Answers2

0

Here are some hacky ways you could do it:

1) When you call reloadData, your cellForRowAtIndexPath: delegate function will get called once for every visible cell. You could count those and then trigger an action after the function has been called enough times.

2) I bet some of the other UITableViewDelegate functions also get called in a deterministic way. Maybe you can just call your refresh function in one of those, perhaps with a small delay.

3) You could also use performSelector:withObject:afterDelay: after [tableView reloadData] and use some hard-coded delay.

Andrew Johnson
  • 13,108
  • 13
  • 75
  • 116
-3

Not an ideal solution but I have gotten around this using a UIView animation and corresponding completion callback. I place this in a UITableView category. Works as you'd expect.

- (void)reloadDataWithCompletion:(void (^)(BOOL finished))completion {
  [UIView animateWithDuration:0.33 animations:^(){
    [self reloadData];
  }completion:completion];
}
RLB
  • 171
  • 1
  • 7