Ios NSFetchedResultsController希望返回的行数准确
我有一个Ios NSFetchedResultsController希望返回的行数准确,ios,core-data,tableview,Ios,Core Data,Tableview,我有一个NSFetchedResultsController配置为在UITableView中加载特定类型的对象。下面是执行此操作的代码示例: __weak __typeof(self)weakSelf = self; [[FSRDataManager sharedManager] loadViolationsForSection:FSRViolationEntityUnitIdAttribute
NSFetchedResultsController
配置为在UITableView
中加载特定类型的对象。下面是执行此操作的代码示例:
__weak __typeof(self)weakSelf = self;
[[FSRDataManager sharedManager] loadViolationsForSection:FSRViolationEntityUnitIdAttribute
success:^(BOOL successful, NSFetchedResultsController *results) {
weakSelf.violations = results;
weakSelf.violations.delegate = weakSelf;
[weakSelf.tableView reloadData];
[weakSelf fetchViolations];
}
failure:^(NSError *error) {
[weakSelf displayAlertForError:error];
[weakSelf fetchViolations];
}];
FRC
有一个sectionNameKeyPath
,因为我想以分段格式显示数据
fetchinflictions
从服务器获取数据并将其存储在持久存储中
并更新托管对象上下文
。在这次更新中,我收到了一个对-controllerWillChange:
和-controllerDidChange:
的委托调用,这是正常的。但是,当发生这些更改时,将调用tableview的-(NSInteger)tableview:(UITableView*)tableview numberOfRowsInSection:(NSInteger)节
在这里,我返回的行数并不总是NSFetchedResultsSectionInfo
对象中的对象数,如下所示:
rows = 1;
for (NSIndexPath *i in self.expandedIndexPaths) {
if (i.section == section) {
id<NSFetchedResultsSectionInfo> s = self.violations.sections[section];
rows += s.numberOfObjects;
}
}
如果我只返回section info对象中的对象数,那么效果很好。有没有办法绕过这个?让我返回我想要的行数 您不能“绕过”这一点,如果不以类似的方式修改FRC委托方法,您就不能使用这种方法。该错误表示您正试图将所有FRC委托回调更改应用于表视图,即使您的行计数方法执行非常特定的筛选。这导致发送到表视图的更改请求与为每个节提供的行数不匹配 最简单的选择是不使用来自FRC的增量更改回调,而只是在FRC报告的每个更改后在表视图上调用
reloadData
如果要为单个更改启用动画,则需要过滤这些更改,并仅将具有相应更改的更改应用于行计数
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.93/UITableView.m:1314
CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. attempt to delete row 6 from section 71 which only contains 1 rows before the update with userInfo (null)