I\'d like to use the NSFetchedResultsControllerRelegate in a CollectionViewController. Therefore I just changed the method for the TableViewController for the CollectionView
Combining a fetched results controller with a collection view is a bit tricky. The problem is explained in
If you're looking for how to get around the
NSInternalInconsistencyException
runtime exception withUICollectionView
, I have an example on GitHub detailing how to queue updates from the NSFetchedResultsControllerDelegate.The problem is that the existing
UITableView
class usesbeginUpdates
andendUpdates
to submit batches to the table view.UICollectionView
has a newperformBatchUpdates:
method, which takes a block parameter to update the collection view. That's sexy, but it doesn't work well with the existing paradigm for NSFetchedResultsController.
Fortunately, that article also provides a sample implementation:
From the README:
This is an example of how to use the new
UICollectionView
withNSFetchedResultsController
. The trick is to queue the updates made through theNSFetchedResultsControllerDelegate
until the controller finishes its updates.UICollectionView
doesn't have the samebeginUpdates
andendUpdates
thatUITableView
has to let it work easily withNSFetchedResultsController
, so you have to queue them or you get internal consistency runtime exceptions.