java pathname,带有sectionNameKeyPath的NSFetchedResultsController

我目前正在开发一个项目,我使用UITableView和NSFetchedResultsController来存储我的数据 . 我面临的问题是使用部分不起作用 .

我想要显示为表的实体具有以下字符:

Channels (字符串)

服务器(字符串)

名称(字符串)

我希望有基于服务器的部分,每个部分中的行是通道 . 布局如下所示:

Server1

通道1

通道2

Server2

通道3

通道4

等等..

但问题是,当我尝试在NSFetchedResultsController中插入/删除/更改元素时,应用程序会获得如下异常:

CoreData:错误:严重的应用程序错误 . 在调用-controllerDidChangeContent:期间,从NSFetchedResultsController的委托中捕获到异常 . 无效更新:无效的节数 . 更新后的表视图中包含的节数(3)必须等于更新前的表视图中包含的节数(2),加上或减去插入或删除的节数(插入0,0删除) . 用户信息(null)

我做了一些研究,人们说这是因为UITableViewController委托首先触发并尝试显示当时不存在的元素/部分 . 我还没有找到解决方案,这就是我在这里的原因 .

这是NSFetchedResultsController的委托方法

- (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];

}

非常感谢

罗伯特

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值