Created
July 5, 2012 18:35
-
-
Save eoghain/3055555 to your computer and use it in GitHub Desktop.
UITableView+FetchedResultsControllerDelegate
This file contains 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 <UIKit/UIKit.h> | |
#import <CoreData/CoreData.h> | |
@interface UITableView (FetchedResultsControllerDelegate) <NSFetchedResultsControllerDelegate> | |
@end | |
@implementation UITableView (FetchedResultsControllerDelegate) | |
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller | |
{ | |
[self beginUpdates]; | |
} | |
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath | |
{ | |
switch (type) | |
{ | |
case NSFetchedResultsChangeInsert: | |
{ | |
[self insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationTop]; | |
break; | |
} | |
case NSFetchedResultsChangeDelete: | |
{ | |
[self deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop]; | |
break; | |
} | |
case NSFetchedResultsChangeUpdate: | |
{ | |
[self reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; | |
break; | |
} | |
case NSFetchedResultsChangeMove: | |
{ | |
[self deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop]; | |
[self insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationTop]; | |
break; | |
} | |
default: | |
break; | |
} | |
} | |
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type | |
{ | |
switch(type) | |
{ | |
case NSFetchedResultsChangeInsert: | |
[self insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationTop]; | |
break; | |
case NSFetchedResultsChangeDelete: | |
[self deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationTop]; | |
break; | |
} | |
} | |
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller | |
{ | |
[self endUpdates]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment