Last active
December 31, 2015 15:19
-
-
Save sebastienwindal/8005997 to your computer and use it in GitHub Desktop.
NSFetchedResultsControllerDelegate implementation quick copy and paste.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #pragma mark NSFetchedResultsControllerDelegate | |
| -(void) controllerWillChangeContent:(NSFetchedResultsController *)controller | |
| { | |
| [self.tableView beginUpdates]; | |
| } | |
| -(void) controllerDidChangeContent:(NSFetchedResultsController *)controller | |
| { | |
| [self.tableView endUpdates]; | |
| } | |
| -(void) controller:(NSFetchedResultsController *)controller | |
| didChangeObject:(id)anObject | |
| atIndexPath:(NSIndexPath *)indexPath | |
| forChangeType:(NSFetchedResultsChangeType)type | |
| newIndexPath:(NSIndexPath *)newIndexPath | |
| { | |
| switch (type) { | |
| case NSFetchedResultsChangeDelete: | |
| { | |
| [self.tableView deleteRowsAtIndexPaths:@[indexPath] | |
| withRowAnimation:UITableViewRowAnimationFade]; | |
| break; | |
| } | |
| case NSFetchedResultsChangeInsert: | |
| { | |
| [self.tableView insertRowsAtIndexPaths:@[newIndexPath] | |
| withRowAnimation:UITableViewRowAnimationRight]; | |
| break; | |
| } | |
| case NSFetchedResultsChangeUpdate: | |
| { | |
| [self.tableView reloadRowsAtIndexPaths:@[indexPath] | |
| withRowAnimation:UITableViewRowAnimationNone ]; | |
| break; | |
| } | |
| case NSFetchedResultsChangeMove: | |
| { | |
| [self.tableView deleteRowsAtIndexPaths:@[indexPath] | |
| withRowAnimation:UITableViewRowAnimationFade]; | |
| [self.tableView insertRowsAtIndexPaths:@[newIndexPath] | |
| withRowAnimation:UITableViewRowAnimationFade]; | |
| break; | |
| } | |
| default: | |
| break; | |
| } | |
| } | |
| -(void) controller:(NSFetchedResultsController *)controller | |
| didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo | |
| atIndex:(NSUInteger)sectionIndex | |
| forChangeType:(NSFetchedResultsChangeType)type | |
| { | |
| switch(type) { | |
| case NSFetchedResultsChangeInsert: | |
| [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; | |
| break; | |
| case NSFetchedResultsChangeDelete: | |
| [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; | |
| break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment