How to use UICollectionView with NSFetchedResultsController
Objective-C
Switch branches/tags
Nothing to show
Pull request Compare This branch is 4 commits ahead, 18 commits behind ashfurrow:master.
Latest commit e2433e6 Apr 15, 2013 Derrick J. Hathaway Derrick J. Hathaway Credit where credit's due.

README.md

UICollectionView+NSFetchedResultsController

A category on UICollectionView providing methods to queue up and commit changes in response to NSFetchedResultsControllerDelegate methods.

Setup

Copy UICollectionView+NSFetchedResultsController.h and UICollectionView+NSFetchedResultsController.m into your project and call the appropriate category methods in your UIFetchedResultsControllerDelegate

#pragma mark - Fetched results controller

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
    // do nothing
}

- (void)controller:(NSFetchedResultsController *)controller
  didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex
     forChangeType:(NSFetchedResultsChangeType)type
{
    [self.collectionView addChangeForSection:sectionInfo
                                     atIndex:sectionIndex
                               forChangeType:type];
}

- (void)controller:(NSFetchedResultsController *)controller
   didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath
     forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath
{
    [self.collectionView addChangeForObjectAtIndexPath:indexPath
                                         forChangeType:type
                                          newIndexPath:newIndexPath];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
    [self.collectionView commitChanges];
}

Credit

Most of the logic for this is taken from this gist. Via Ash Furrow.