mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-24 04:46:01 +08:00
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:
committed by
Blake Watters
parent
61480a5b4c
commit
d652452481
@@ -28,6 +28,7 @@ typedef UIView*(^RKFetchedResultsTableViewViewForHeaderInSectionBlock)(NSUIntege
|
||||
NSFetchedResultsController* _fetchedResultsController;
|
||||
BOOL _showsSectionIndexTitles;
|
||||
NSArray* _arraySortedFetchedObjects;
|
||||
BOOL _isEmptyBeforeAnimation;
|
||||
}
|
||||
|
||||
@property (nonatomic, readonly) NSFetchedResultsController* fetchedResultsController;
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user