Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
How to use UICollectionView with NSFetchedResultsController
Objective-C
Branch: master
Pull request Compare This branch is 4 commits ahead, 18 commits behind ashfurrow:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
SampleCollectionView
README.md
UICollectionView+NSFetchedResultsController.h
UICollectionView+NSFetchedResultsController.m

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.

Something went wrong with that request. Please try again.