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

前端之家收集整理的这篇文章主要介绍了关于删除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/199258.html

猜你在找的Sqlite相关文章