<small id='vD8Df'></small><noframes id='vD8Df'>

    <i id='vD8Df'><tr id='vD8Df'><dt id='vD8Df'><q id='vD8Df'><span id='vD8Df'><b id='vD8Df'><form id='vD8Df'><ins id='vD8Df'></ins><ul id='vD8Df'></ul><sub id='vD8Df'></sub></form><legend id='vD8Df'></legend><bdo id='vD8Df'><pre id='vD8Df'><center id='vD8Df'></center></pre></bdo></b><th id='vD8Df'></th></span></q></dt></tr></i><div id='vD8Df'><tfoot id='vD8Df'></tfoot><dl id='vD8Df'><fieldset id='vD8Df'></fieldset></dl></div>
  1. <legend id='vD8Df'><style id='vD8Df'><dir id='vD8Df'><q id='vD8Df'></q></dir></style></legend><tfoot id='vD8Df'></tfoot>

        <bdo id='vD8Df'></bdo><ul id='vD8Df'></ul>

      CollectionView 的 NSFetchedResultsContollerDelegate

      时间:2023-07-28
        <tbody id='msbVq'></tbody>
        <legend id='msbVq'><style id='msbVq'><dir id='msbVq'><q id='msbVq'></q></dir></style></legend>
          <bdo id='msbVq'></bdo><ul id='msbVq'></ul>

          • <i id='msbVq'><tr id='msbVq'><dt id='msbVq'><q id='msbVq'><span id='msbVq'><b id='msbVq'><form id='msbVq'><ins id='msbVq'></ins><ul id='msbVq'></ul><sub id='msbVq'></sub></form><legend id='msbVq'></legend><bdo id='msbVq'><pre id='msbVq'><center id='msbVq'></center></pre></bdo></b><th id='msbVq'></th></span></q></dt></tr></i><div id='msbVq'><tfoot id='msbVq'></tfoot><dl id='msbVq'><fieldset id='msbVq'></fieldset></dl></div>

            1. <tfoot id='msbVq'></tfoot>

                <small id='msbVq'></small><noframes id='msbVq'>

              1. 本文介绍了CollectionView 的 NSFetchedResultsContollerDelegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我想在 CollectionViewController 中使用 NSFetchedResultsControllerRelegate.因此,我只是为 CollectionView 更改了 TableViewController 的方法.

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

                (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
                       atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
                
                    switch(type) {
                        case NSFetchedResultsChangeInsert:
                            [self.collectionView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex]];
                            break;
                
                        case NSFetchedResultsChangeDelete:
                            [self.collectionView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] ];
                
                       break;
                    }
                }
                
                
                (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
                   atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
                  newIndexPath:(NSIndexPath *)newIndexPath {
                
                  UICollectionView *collectionView = self.collectionView;
                
                  switch(type) {
                
                    case NSFetchedResultsChangeInsert:
                        [collectionView insertItemsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]];
                        break;
                
                    case NSFetchedResultsChangeDelete:
                        [collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
                        break;
                
                    case NSFetchedResultsChangeUpdate:
                        [collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
                        break;
                
                    case NSFetchedResultsChangeMove:
                        [collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
                        [collectionView insertItemsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]];
                        break;
                  }
                }
                
                (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
                   [self.collectionView reloadData];
                }
                

                但我不知道如何处理 WillChangeContent (beginUpdates for TableView) 和 DidChangeContent (<TableView) 的 CollectionView 的 code>endUpdates.

                But I do not know how to handle the WillChangeContent (beginUpdates for TableView) and DidChangeContent (endUpdates for TableView) for a CollectionView.

                一切正常,除非我将一个项目从一个部分移动到另一个部分.然后我收到以下错误.

                Everything works fine except when I move one item from one section to another section. Then I get the following error.

                这通常是 NSManagedObjectContextObjectsDidChangeNotification 观察者中的错误.无效更新:第 0 节中的项目数无效....

                This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. Invalid update: invalid number of items in section 0....

                知道如何解决这个问题吗?

                Any idea how can I solve this issue?

                推荐答案

                将获取的结果控制器与集合视图结合起来有点棘手.问题在

                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

                如果您正在寻找如何绕过NSInternalInconsistencyException 运行时异常UICollectionView,我在 GitHub 上有一个示例,详细说明了如何排队从 NSFetchedResultsControllerDelegate 更新.

                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.

                问题是现有的 UITableView 类使用 beginUpdatesendUpdates 将批次提交到表格视图.UICollectionView有一个新的 performBatchUpdates: 方法,它接受一个块参数更新集合视图.这很性感,但效果不佳使用 NSFetchedResultsController 的现有范例.

                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

                来自自述文件:

                这是一个如何使用新的 UICollectionView 的示例NSFetchedResultsController.诀窍是将所做的更新排队通过 NSFetchedResultsControllerDelegate 直到控制器完成它的更新.UICollectionView 不一样beginUpdatesendUpdates UITableView 必须让它轻松工作使用 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.

                这篇关于CollectionView 的 NSFetchedResultsContollerDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:从应用委托中获取当前视图控制器 下一篇:在 Objective C 中调用另一个类的方法

                相关文章

                  • <bdo id='y5MkY'></bdo><ul id='y5MkY'></ul>

                    <small id='y5MkY'></small><noframes id='y5MkY'>

                  1. <i id='y5MkY'><tr id='y5MkY'><dt id='y5MkY'><q id='y5MkY'><span id='y5MkY'><b id='y5MkY'><form id='y5MkY'><ins id='y5MkY'></ins><ul id='y5MkY'></ul><sub id='y5MkY'></sub></form><legend id='y5MkY'></legend><bdo id='y5MkY'><pre id='y5MkY'><center id='y5MkY'></center></pre></bdo></b><th id='y5MkY'></th></span></q></dt></tr></i><div id='y5MkY'><tfoot id='y5MkY'></tfoot><dl id='y5MkY'><fieldset id='y5MkY'></fieldset></dl></div>
                    <tfoot id='y5MkY'></tfoot>
                    <legend id='y5MkY'><style id='y5MkY'><dir id='y5MkY'><q id='y5MkY'></q></dir></style></legend>