Add handling for animating out the empty item when going from an empty table to a populated table. Fixes an issue where table animation was breaking due to unbalanced insert/deletes when the emptyItem was showing before a table update.

This commit is contained in:
Jeff Arena
2011-11-19 13:26:37 -05:00
committed by Blake Watters
parent 61480a5b4c
commit d652452481
2 changed files with 10 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ typedef UIView*(^RKFetchedResultsTableViewViewForHeaderInSectionBlock)(NSUIntege
NSFetchedResultsController* _fetchedResultsController;
BOOL _showsSectionIndexTitles;
NSArray* _arraySortedFetchedObjects;
BOOL _isEmptyBeforeAnimation;
}
@property (nonatomic, readonly) NSFetchedResultsController* fetchedResultsController;

View File

@@ -142,6 +142,10 @@
[self isEmptyRow:indexPath.row]);
}
- (NSIndexPath *)emptyItemIndexPath {
return [NSIndexPath indexPathForRow:0 inSection:0];
}
- (NSIndexPath *)fetchedResultsIndexPathForIndexPath:(NSIndexPath *)indexPath {
if (([self isEmpty] && self.emptyItem &&
[self isEmptySection:indexPath.section] &&
@@ -479,6 +483,7 @@
- (void)controllerWillChangeContent:(NSFetchedResultsController*)controller {
RKLogTrace(@"Beginning updates for fetchedResultsController (%@). Current section count = %d (resource path: %@)", controller, [[controller sections] count], _resourcePath);
[self.tableView beginUpdates];
_isEmptyBeforeAnimation = [self isEmpty];
}
- (void)controller:(NSFetchedResultsController*)controller
@@ -547,6 +552,10 @@
- (void)controllerDidChangeContent:(NSFetchedResultsController*)controller {
RKLogTrace(@"Ending updates for fetchedResultsController (%@). New section count = %d (resource path: %@)",
controller, [[controller sections] count], _resourcePath);
if (self.emptyItem && ![self isEmpty] && _isEmptyBeforeAnimation) {
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[self emptyItemIndexPath]]
withRowAnimation:UITableViewRowAnimationFade];
}
[self.tableView endUpdates];
[self didFinishLoad];
}