NSFetchedResultsContollerDelegate for CollectionView

前端 未结 6 1067
悲哀的现实
悲哀的现实 2020-11-30 21:10

I\'d like to use the NSFetchedResultsControllerRelegate in a CollectionViewController. Therefore I just changed the method for the TableViewController for the CollectionView

6条回答
  •  自闭症患者
    2020-11-30 21:15

    Combining a fetched results controller with a collection view is a bit tricky. The problem is explained in

    • http://ashfurrow.com/blog/how-to-use-nsfetchedresultscontroller-with-uicollectionview

    If you're looking for how to get around the NSInternalInconsistencyException runtime exception with UICollectionView, I have an example on GitHub detailing how to queue updates from the NSFetchedResultsControllerDelegate.

    The problem is that the existing UITableView class uses beginUpdates and endUpdates to submit batches to the table view. UICollectionView has a new performBatchUpdates: 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:

    • https://github.com/AshFurrow/UICollectionView-NSFetchedResultsController

    From the README:

    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.

提交回复
热议问题