Uitableview 带有sectionNameKeyPath的NSFetchedResultsController
我目前正在从事一个项目,我使用UITableView和NSFetchedResultsController来存储我的数据。我面临的问题是节的使用不起作用 我希望显示为表格的实体具有以下特征:Uitableview 带有sectionNameKeyPath的NSFetchedResultsController,uitableview,core-data,nsfetchedresultscontroller,Uitableview,Core Data,Nsfetchedresultscontroller,我目前正在从事一个项目,我使用UITableView和NSFetchedResultsController来存储我的数据。我面临的问题是节的使用不起作用 我希望显示为表格的实体具有以下特征: 频道(字符串) 服务器(字符串) 名称(字符串) 我希望有基于服务器的部分,每个部分中的行是通道。布局将如下所示: 服务器1 通道1 渠道2 服务器2 渠道3 渠道4 等等 但问题是,当我尝试在NSFetchedResultsController中插入/删除/更改元素时,应用程序会出现如下异常: C
- 频道(字符串)
- 服务器(字符串)
- 名称(字符串)
- 服务器1
通道1
渠道2 - 服务器2
渠道3
渠道4
等等
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView beginUpdates];
}
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
UITableView *tableView = self.tableView;
NSLog(@"--- Core Data noticed change");
switch(type) {
case NSFetchedResultsChangeInsert:
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeUpdate:
[self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView endUpdates];
}
非常感谢Robert您还必须实施
controller:didChangeSection:atIndex:forChangeType:
委托函数,否则将不会通知表视图核心数据存储中插入或删除的节
您可以在中找到一个示例实现。@user1285341:不客气。-请不要忘记“接受”答案,点击答案左边的复选框,谢谢!