首页 > 解决方案 > NSFetchedResultController 委托的顺序 didChange: atSectionIndex:

问题描述

我有一个奇怪的情况,我问自己是否做错了什么。我分配了一个 NSFetchedResultsController 和一个委托。委托接收到已正确添加部分的函数调用,但消息的顺序似乎未定义。

    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>,
                    didChange sectionInfo: NSFetchedResultsSectionInfo,
                    atSectionIndex sectionIndex: Int,
                    for type: NSFetchedResultsChangeType) 

假设我的初始提取导致 3 个部分 [0,1,2]。现在我收到有关更改的更新,如下所示:

我正在尝试根据更改跟踪视图模型,所以我不知道我需要在这里做什么。如何在添加第 3 节之前添加第 4 节。问题是,如果我只添加一个占位符第 3 节,然后添加第 4 节4.

文档说明了订单,但我希望更新是有序的,以便我可以跟踪对本地数组的更改。

任何提示表示赞赏。

标签: ioscore-datansfetchedresultscontroller

解决方案


NSFetchedResultsController专门设计/实现/测试以驱动UITableView. 从文档:

While table views can be used in several ways, fetched results controllers primarily assist you with a primary list view.

要回答您的问题,我认为您没有做错任何事情,但我认为您正在尝试对UITableView' 实施中的一些秘密进行逆向工程。


推荐阅读