5

When one uses a UITableViewRowAnimation upon deletion of a row or the addition of a row, sometimes if this row is at the extremes of the tableview the table scrolls.

Yet, even though it scrolls it doesn't seem to call scrollViewDidScroll: on the delegate.

For example, I have the following code in my delegate.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"Scrolling %f", scrollView.contentOffset.y);
}

Which gets called if the user scrolls. But when I have a deletion of a row:

[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];

The scrollViewDidScroll: method is not called at all.

Is there any way to ensure that this gets called while the UITableView is animating?

Thanks!

Arjun Mehta
  • 2,500
  • 1
  • 24
  • 40

2 Answers2

0

In case you weren't aware, scrollViewDidScroll is only called in response to user interaction with a scroll view (or, in this case, table view). It is not called in response to scrolling due to animations. This behavior is fixed. You'll need to find another way to achieve what you're after. Perhaps this existing question might be of use:

How to make UIScrollView send scrollViewDidScroll messages during animations

Community
  • 1
  • 1
lxt
  • 31,146
  • 5
  • 78
  • 83
  • I had come across that question, but couldn't quite understand how to tie the deleteRowsAtIndexPaths UITableViewRowAnimationFade to a block animation instead of the built in method. – Arjun Mehta Mar 26 '14 at 00:10
  • 4
    By the way I don't know if your comment about it being called only in response to user interaction is correct. If you do something like [scrollView setContentOffset:aCGPoint animated:YES]; scrollViewDidScroll does get triggered. – Arjun Mehta Mar 26 '14 at 15:21
0

You can use the following approach instead.

    [CATransaction setCompletionBlock: ^{
        // do stuff
    }];

    [CATransaction begin];

    [tableView beginUpdates];
    [tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
    [tableView endUpdates];

    [CATransaction commit];
fotios
  • 204
  • 4
  • 10
  • Its – unfortunately, but as the name implies – a *completion* block. So it will fire after the scrolling is done. `-scrollViewDidScroll:` instead, is used to catch intermediate events as well to – for example – create parallax effects. – Julian F. Weinert Aug 26 '15 at 09:27