关于删除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找不到了就越界。。

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能