从表格视图中删除单元格-错误-提供了代码 [英] Deleting cell from a tableview - Error - Code provided

查看:37
本文介绍了从表格视图中删除单元格-错误-提供了代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义单元格,我正在向其添加一个段控件.

I have a custom cell and i am adding a segment control to it.

-(void)segmentclicked:(id)sender{


        UISegmentedControl *segmentC = (UISegmentedControl *)sender;

        CustomCell *cell=(CustomCell *)segmentC.superview.superview;

        NSIndexPath *indexPath = [self.table indexPathForCell:cell];

        NSMutableArray *discardarr = [NSMutableArray array];

        [discardarr addObject:[self.entries objectAtIndex:indexPath.row]];

        [self.table beginUpdates];

        [self.itemsArray removeObjectsInArray:discardarr ]; 

        [self.table deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]  withRowAnimation:NO];         

        self.entries = [NSArray arrayWithArray:self.itemsArray];

        [self.table endUpdates];

        [self.table reloadData];


    }
}

我收到以下错误;

"NSInternalInconsistencyException",原因:无效更新:第0节中的行数无效.更新(10)之后现有节中包含的行数必须等于(0)前该节中包含的行数.更新(10),加上或减去从该部分插入或删除的行数(已插入0,已删除1),以及加上或减去移入或移出该部分的行数(0移入,0移出).'

'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (10) must be equal to the number of rows contained in that section before the update (10), 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).'

* 首先抛出调用堆栈:

1.)我怎么能摆脱这个,我相信我已经做了相应的一切.我什至尝试在 [self.table endUpdates]; 上方添加行 [self.table reloadData]; ,仍然没有任何变化.帮助

1.) how could i get rid of this, i believe i have done everything accordingly. I have even tried adding the line [self.table reloadData]; above [self.table endUpdates]; , still there isn't any change. Help

推荐答案

一旦您通过此行删除代码中的行 [self.table deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:NO];

once you delete the rows in your code by this line [self.table deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:NO];

您的tableview再次检查数据源,以查看行中的节数和节中的行数.错误的原因是,在检查中,删除的元素仍然作为数据源元素存在,表视图应该显示该数据源元素,但是您已调用删除该行.

your tableview again checks with the datasource to see the number of sections in the row and the number of rows in the sections.. The error is because in that checking your deleted element still exists as a datasource element which the tableview should show but you have called delete that row.

例如.

在我的行数中,我返回7.

in my number of rows i return 7 .

但是如果我删除一行,我必须返回6 ..但是您的行可能仍然是7 ..

but if i delete a row i have to make this return 6..but your still might be 7..

(通常返回值是一些[数组数],我刚刚以return 7为例)

这篇关于从表格视图中删除单元格-错误-提供了代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆