Database Reference
In-Depth Information
case
NSFetchedResultsChangeInsert:
[[self tableView] insertSections:indexSet
withRowAnimation:UITableViewRowAnimationFade];
break
;
case
NSFetchedResultsChangeDelete:
[[self tableView] deleteSections:indexSet
withRowAnimation:UITableViewRowAnimationFade];
break
;
}
}
Here we use a switch to determine what the change type is and pass it along
to the
UITableView
.
-controller: didChangeObject: atIndexPath: forChangeType: newIndexPath:
This is the most complex method in the
NSFetchedResultsControllerDelegate
protocol.
In this method, we are notified of any changes to any data object. There are
four types of changes that we need to react to, listed next.
- (
void
)controller:(NSFetchedResultsController *)controller
didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath
forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
NSArray *newArray = [NSArray arrayWithObject:newIndexPath];
NSArray *oldArray = [NSArray arrayWithObject:indexPath];
switch
(type) {
case
NSFetchedResultsChangeInsert:
[[self tableView] insertRowsAtIndexPaths:newArray
withRowAnimation:UITableViewRowAnimationFade];
break
;
case
NSFetchedResultsChangeDelete:
[[self tableView] deleteRowsAtIndexPaths:oldArray
withRowAnimation:UITableViewRowAnimationFade];
break
;
case
NSFetchedResultsChangeUpdate:
{
UITableViewCell *cell = nil;
NSManagedObject *object = nil;
cell = [[self tableView] cellForRowAtIndexPath:indexPath];
object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
[[cell textLabel] setText:[object valueForKey:@
"name"
]];
break
;
}
case
NSFetchedResultsChangeMove: