主详细信息申请 -
我有一个UITableViewController
由一个NSFetchedResultsController
及其委托方法。我在表格视图的第一部分还有一个额外的单元格,其中有一个UIWebView
其中显示嵌入视频。该单元格不属于NSFetchedResultsController
。我将其添加到一个IF
声明时-tableView cellForRowAtIndexPath
被调用,检查它是否是第一部分和第一行。大部分情况下一切都运转良好。我可以选择一行并将其显示在DetailViewController
,我可以从tableView
,我可以更改其中的信息DetailViewController
and the tableViewCell
标签更新没有任何问题。
MY ISSUE
我唯一一次对它的设置方式有疑问是当我从第一部分中删除最后一个对象时tableView
.
错误
CoreData:错误:严重的应用程序错误。捕获了异常
在调用期间从 NSFetchedResultsController 的委托
-controllerDidChangeContent:。无效更新:第 0 节中的行数无效。现有节中包含的行数
更新后 (3) 必须等于包含的行数
更新之前的部分 (2),加上或减去行数
从该部分插入或删除(0 插入,0 删除)并加上
或减去移入或移出该部分的行数(0 移动
入,0 移出)。与用户信息(空)
CODE
节中的行数
这是我检查视频是否可用以及该部分是否为 0 则返回 1 行的地方。否则返回对象计数NSFetchedResultsController
。我假设这就是我的问题所在。但是,我不知道如何解决它。因为我已经将它管理了NSFetchedResultsController
委托方法在 switch 语句的“类型”内部我可以做些什么吗?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0 && self.videoInfoReceived == YES) {
id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [secInfo numberOfObjects] + 1;
} else {
id <NSFetchedResultsSectionInfo> secInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
return [secInfo numberOfObjects];
}
}
NSFetchedResultsController 委托
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
{
switch(type) {
case NSFetchedResultsChangeInsert:
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"didChangeSection - ChangeInsert");
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"didChangeSection - ChangeDelete");
break;
}
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
UITableView *tableView = self.tableView;
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"didChangeObject - ChangeInsert");
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"didChangeObject - ChangeDelete");
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
NSLog(@"didChangeObject - ChangeUpdate");
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"didChangeObject - ChangeMove");
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView endUpdates];
}
您需要更多条件代码来检查发送的任何索引路径是否适用于第一个(零)部分。如果是,则 FRC 被赋予“错误”的行号,因为您已告诉表视图一行计数,而 FRC 理解的是不同的行计数。
基本上,无论你在哪里收到索引路径从表上看,检查该部分,如果== 0
,创建一个具有相同部分的新索引路径并row - 1
并使用它来访问 FRC 中的对象。
相反,当您收到索引路径时来自FRC你需要row + 1
然后您可以使用它来要求表视图插入/删除/移动。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)