mirror of
https://github.com/zhigang1992/RestKit.git
synced 2026-04-23 20:31:13 +08:00
Fix issue with _arraySortedFetchedObjects in cases where updates were received via the NSFetchedResultsControllerDelegate and were being then not being applied to the sorted array
This commit is contained in:
committed by
Blake Watters
parent
d20f44804e
commit
4196b66f9d
@@ -31,6 +31,7 @@
|
||||
|
||||
@interface RKFetchedResultsTableController ()
|
||||
- (void)performFetch;
|
||||
- (void)updateSortedArray;
|
||||
@end
|
||||
|
||||
@implementation RKFetchedResultsTableController
|
||||
@@ -87,6 +88,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)updateSortedArray {
|
||||
[_arraySortedFetchedObjects release];
|
||||
_arraySortedFetchedObjects = nil;
|
||||
|
||||
if (_sortSelector || _sortComparator) {
|
||||
if (_sortSelector) {
|
||||
_arraySortedFetchedObjects = [[_fetchedResultsController.fetchedObjects sortedArrayUsingSelector:_sortSelector] retain];
|
||||
} else if (_sortComparator) {
|
||||
_arraySortedFetchedObjects = [[_fetchedResultsController.fetchedObjects sortedArrayUsingComparator:_sortComparator] retain];
|
||||
}
|
||||
|
||||
NSAssert(_arraySortedFetchedObjects.count == _fetchedResultsController.fetchedObjects.count,
|
||||
@"sortSelector or sortComparator sort resulted in fewer objects than expected");
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isHeaderSection:(NSUInteger)section {
|
||||
return (section == 0);
|
||||
}
|
||||
@@ -224,17 +241,7 @@
|
||||
_fetchedResultsController.delegate = self;
|
||||
|
||||
[self performFetch];
|
||||
|
||||
[_arraySortedFetchedObjects release];
|
||||
_arraySortedFetchedObjects = nil;
|
||||
|
||||
if (_sortSelector || _sortComparator) {
|
||||
if (_sortSelector) {
|
||||
_arraySortedFetchedObjects = [[_fetchedResultsController.fetchedObjects sortedArrayUsingSelector:_sortSelector] retain];
|
||||
} else if (_sortComparator) {
|
||||
_arraySortedFetchedObjects = [[_fetchedResultsController.fetchedObjects sortedArrayUsingComparator:_sortComparator] retain];
|
||||
}
|
||||
}
|
||||
[self updateSortedArray];
|
||||
|
||||
[self.tableView reloadData];
|
||||
[self didFinishLoad];
|
||||
@@ -580,9 +587,10 @@
|
||||
controller, [[controller sections] count], _resourcePath);
|
||||
if (self.emptyItem && ![self isEmpty] && _isEmptyBeforeAnimation) {
|
||||
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:[self emptyItemIndexPath]]
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
withRowAnimation:UITableViewRowAnimationFade];
|
||||
}
|
||||
[self.tableView endUpdates];
|
||||
[self updateSortedArray];
|
||||
[self.tableView endUpdates];
|
||||
[self didFinishLoad];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user