加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-12 19:37:35 所属栏目:百科 来源:网络整理
导读:删除某一tableview的某一行并且删除对应数据。 先删数据库 再删table view! - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"%s",__func_

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读