问题
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!
回答1:
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
回答2:
You can use the following approach instead.
[CATransaction setCompletionBlock: ^{
// do stuff
}];
[CATransaction begin];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[tableView endUpdates];
[CATransaction commit];
来源:https://stackoverflow.com/questions/22648168/scrollviewdidscroll-on-uitableviewrowanimation