Dru*_*rux 5 core-data uitableview uikit nsfetchedresultscontroller ios
我收到错误“尝试删除第 1 节,但在使用 userInfo 更新之前只有 1 个节”,这显然是由调用reloadSections:withRowAnimation:
. 这是怎么发生的,因为重新加载不是删除,或者是部分删除?
当回滚 a 中的更改(UITableViewController
其数据源部分由 a 支持)时会发生这种UIFetchedResultsController
情况(表的第一个部分包含常量行;其其余部分对应于 sUIFetchedResultController
部分:在本例中,有两个这样的部分,每部分一行。UITableViewController
还担任 的UIFetchedResultsController
代表。
在回滚期间(以取消删除最后两个部分),委托会收到以下调用:
controllerWillChangeContent:
; numberOfSectionsInTableView
是 1;代表通话beginUpdates
controller:didChangeSection:atIndex:forChangeType:
宣布NSFetchedResultsChangeInsert
第 1 条;numberOfSectionsInTableView is 3; delegate calls
insertSections:withRowAnimation: for section 2,
reloadSections:withRowAnimation:` 第 1 节controller:didChangeSection:atIndex:forChangeType:
宣布NSFetchedResultsChangeInsert
第 0 节;代表呼吁insertSections:withRowAnimation:
第 1 节,reloadSections:withRowAnimation:
第 0 节controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
宣布NSFetchedResultsChangeInsert
为indexPath
(1,0);代表要求insertRowsAtIndexPaths:withRowAnimation:
( indexPath
2,0)controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:
宣布NSFetchedResultsChangeInsert
为indexPath
(0,0);代表要求insertRowsAtIndexPaths:withRowAnimation:
( indexPath
1,0)controllerDidChangeContent:
; 委托调用endUpates
,这会导致此错误:尝试删除第 1 节,但在更新 userInfo 之前只有 1 节
如果委托没有reloadSections:withRowAnimation
按照指示进行调用,则不会发生错误。
在这种特定情况下,是什么原因导致错误以及如何防止它?(顺便说一句,在这种情况下,需要重新加载才能更新相邻部分中页眉和页脚的标题。)
更新我认为问题可能与以下事实有关:在一个步骤中numberOfSectionsInTableView
从 1 跳回到 3 (由于) ,而实际部分(和行)的数量在和之间的“括号”内逐渐增长。但是,括号不正是为了允许数据源中的项目数与表中的项目数之间存在临时差异吗?我的定义如下:rollback
controllerWillChangeContent:
controllerWillChangeContent:
controllerDidChangeContent:
numberOfSectionInTableView:
- (NSInteger)numberOfSectionsInTableView: (UITableView *)tableView {
return 1 + self.fetchedResultsController.sections.count;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3364 次 |
最近记录: |