Created
February 21, 2015 20:56
-
-
Save mdziadkowiec/424c9b9c7c8cab0ade01 to your computer and use it in GitHub Desktop.
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
#import "CoreDataTableViewController.h" | |
@implementation CoreDataTableViewController | |
#pragma mark - NSFetchedResultsControllerDelegate | |
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller | |
{ | |
[self.tableView beginUpdates]; | |
} | |
- (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; | |
} | |
} | |
- (void)controller:(NSFetchedResultsController *)controller | |
didChangeObject:(id)anObject | |
atIndexPath:(NSIndexPath *)indexPath | |
forChangeType:(NSFetchedResultsChangeType)type | |
newIndexPath:(NSIndexPath *)newIndexPath | |
{ | |
switch(type) | |
{ | |
case NSFetchedResultsChangeInsert: | |
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
break; | |
case NSFetchedResultsChangeDelete: | |
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
break; | |
case NSFetchedResultsChangeUpdate: | |
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
break; | |
case NSFetchedResultsChangeMove: | |
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; | |
break; | |
} | |
} | |
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller | |
{ | |
[self.tableView endUpdates]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment