Skip to content
This repository has been archived by the owner on Dec 26, 2018. It is now read-only.

radianttap/UICollectionView-NSFetchedResultsController

 
 

Repository files navigation

Error in user YAML: (<unknown>): did not find expected comment or line break while scanning a block scalar at line 1 column 1
---
> Note: this is abandoned. I don't recommend to use it in new projects.
---

UICollectionView+NSFetchedResultsController

This is an example of how to use the new UICollectionView with NSFetchedResultsController. The trick is to queue the updates made through the NSFetchedResultsControllerDelegate until the controller finishes its updates. UICollectionView doesn't have the same beginUpdates and endUpdates that UITableView has to let it work easily with NSFetchedResultsController, so you have to queue them or you get internal consistency runtime exceptions.

Setup

  • [CocoaPods]
    Add pod 'UICollectionView+NSFetchedResultsController' to your podfile.
  • Manual
    Copy UICollectionView+NSFetchedResultsController.h/m to your project.

Usage

Just include the header and write your NSFetchedResultsControllerDelegate methods like this:

- (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];
}

About

How to use UICollectionView with NSFetchedResultsController

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 92.2%
  • Ruby 7.8%