微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

关于删除cell某行和清除sqlite对应数据问题

删除某一tableview的某一行并且删除对应数据。


先删数据库 再删table view!

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSLog(@"%s",__func__);
    
    if(editingStyle == UITableViewCellEditingStyleDelete){

        //同步数据
        makeupModel *makeup = self.makeup[indexPath.row];
        [makeup deleteObject];
        //删除联系人
        
        
        
         [self.makeup removeObjectAtIndex:indexPath.row];
        //刷新表格
        NSIndexPath *deleteIndex = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
        
        [self.tableView deleteRowsAtIndexPaths:@[deleteIndex]
                              withRowAnimation:UITableViewRowAnimationFade];

        
    }
    
    
    
}

否则会报错:


uncaught exception 'NSInternalInconsistencyException',reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (3),plus or minus the number of rows inserted or deleted from that section (0 inserted,1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in,0 moved out).'


deleteRowsAtIndexPaths后Section里面的rows数量,和系统调用numberOfRowsInSection时rows数量不一致



我还遇到了一个越界的报错,估计也和代码顺序有关系 如果先删除这一行 在删除数据的时候,因为这行已经删除了,对应的indexpath.row找不到了就越界。。

原文地址:https://www.jb51.cc/sqlite/199258.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐