我有一个自定义单元格,我正在为它添加一个段控件。从表格视图中删除单元格 - 错误 - 提供的代码
-(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)之后包含在现有段的行数必须等于包含在该行数(10)之前的部分,加上或减去从该部分插入或删除的行数(插入0,删除1),加上或减去移入或移出该部分的行数(移入0,移动0出)。”
*第一掷调用堆栈:
1)我怎么能摆脱这一点,我相信我有相应所做的一切。我甚至试过在[self.table endUpdates];
以上加[self.table reloadData];
这一行,仍然没有任何变化。帮助
我编辑了我的代码,看看'numberOfRowsInSection'方法。我做对了。你能在我的代码中发现任何异常吗?帮助:( – shajem 2012-02-06 16:53:09
应该'self.entries = [NSArray arrayWithArray:self.itemsArray]; '上面'deleteRowsAtIndexPaths' ?? – shajem 2012-02-06 16:54:45
把一个NSLog之前返回[self.entries count];检查你的计数..让一个断点在它上面,并检查它的值,然后按下删除,然后按下删除..它应该比以前少1 ..如果它不是元素不会在您的数组中删除.. – Shubhank 2012-02-06 16:55:26