coreData的错误总结-1

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    
    
    [self.tableView endUpdates];
}
在操作数据的时候,增删改查,会crash在这个方法里面,打印日志显示如下:

CoreData: error: Serious application error.  An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:.  attempt to insert row 1 into section 1, but there are only 1 rows in section 1 after the update with userInfo (null)
网上出现类似问题:http://blog.csdn.net/gukong/article/details/34161385  参考,共同解决这个问题。

出现这个问题的主要原因就是
- (void)controller:(NSFetchedResultsController *)controller
  didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex
     forChangeType:(NSFetchedResultsChangeType)type
{
    
    [self.tableView beginUpdates];
    
    NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:sectionIndex];
    
    switch (type) {
        case NSFetchedResultsChangeInsert: {
            [self.tableView insertSections:indexSet
                          withRowAnimation:UITableViewRowAnimationFade];
            break;
        }
        case NSFetchedResultsChangeDelete:{
            [self.tableView deleteSections:indexSet
                          withRowAnimation:UITableViewRowAnimationFade];
            break;
        }
        default:
            break;
    }
    
    [self.tableView endUpdates];
}


就是tablview的一些删除,更新,插入,的动画操作代码,应该放入到, [self.tableView beginUpdates];[self.tableView endUpdates];和这个方法中间,一般,在添加,删除,选择 tableView中使用,并实现动画效果。 在动画块内,不建议使用reloadData方法,如果使用,会影响动画。 一般在UITableView执行:删除行,插入行,删除分组,插入分组时,使用!用来协调UITableView的动画效果。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值