我有一個自定義單元格,我正在爲它添加一個段控件。從表格視圖中刪除單元格 - 錯誤 - 提供的代碼
-(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