Fix fetching will continually trigger in a loop after reaching end of content

Don't schedule a new check for a batch fetch if no data changed previous batch fetch
This commit is contained in:
Michael Schneider
2016-04-12 17:10:22 -07:00
parent 364013a333
commit d0023a97f7
2 changed files with 22 additions and 11 deletions

View File

@@ -730,8 +730,13 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
}
}
- (void)_scheduleCheckForBatchFetching
- (void)_scheduleCheckForBatchFetchingForNumberOfChanges:(NSUInteger)changes
{
// Prevent fetching will continually trigger in a loop after reaching end of content and no new content was provided
if (changes == 0) {
return;
}
// Push this to the next runloop to be sure the scroll view has the right content size
dispatch_async(dispatch_get_main_queue(), ^{
[self _checkForBatchFetching];
@@ -904,7 +909,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
BOOL preventAnimation = animationOptions == UITableViewRowAnimationNone;
ASPerformBlockWithoutAnimation(preventAnimation, ^{
[super insertRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOptions];
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:indexPaths.count];
});
if (_automaticallyAdjustsContentOffset) {
@@ -924,7 +929,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
BOOL preventAnimation = animationOptions == UITableViewRowAnimationNone;
ASPerformBlockWithoutAnimation(preventAnimation, ^{
[super deleteRowsAtIndexPaths:indexPaths withRowAnimation:(UITableViewRowAnimation)animationOptions];
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:indexPaths.count];
});
if (_automaticallyAdjustsContentOffset) {
@@ -945,7 +950,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
BOOL preventAnimation = animationOptions == UITableViewRowAnimationNone;
ASPerformBlockWithoutAnimation(preventAnimation, ^{
[super insertSections:indexSet withRowAnimation:(UITableViewRowAnimation)animationOptions];
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:indexSet.count];
});
}
@@ -961,7 +966,7 @@ static NSString * const kCellReuseIdentifier = @"_ASTableViewCell";
BOOL preventAnimation = animationOptions == UITableViewRowAnimationNone;
ASPerformBlockWithoutAnimation(preventAnimation, ^{
[super deleteSections:indexSet withRowAnimation:(UITableViewRowAnimation)animationOptions];
[self _scheduleCheckForBatchFetching];
[self _scheduleCheckForBatchFetchingForNumberOfChanges:indexSet.count];
});
}