我正在尝试从UITableView中删除一些行,这是我的代码......
[self.responsesTableView beginUpdates];
[self.responsesTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.processingIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self. responsesTableView endUpdates];
noOfRsponses --;
if (self.segFrndEveryone.selectedSegmentIndex == 0) {
[self.arrFriendComments removeObjectAtIndex:self.processingIndexPath.row];
}else {
[self.arrAllComments removeObjectAtIndex:self.processingIndexPath.row];
}
其中一个数组是我选择的段上的数据源。 我收到以下错误,不知道如何处理此问题。
更新后现有部分中包含的行数 (9)必须等于该部分中包含的行数 在更新(9)之前,加上或减去插入的行数或 从该部分删除(0插入,1删除)和加号或减号 移入或移出该部分的行数(0移入,0 搬出去了。'
答案 0 :(得分:3)
在对UITableView
进行手动更改之前,您应该更新数据源。
// update the data source for the table change
noOfRsponses--;
NSMutableArray *targetArray = (self.segFrndEveryone.selectedSegmentIndex == 0) ? self.arrFriendComments : self.arrAllComments;
[targetArray removeObjectAtIndex:self.processingIndexPath.row];
// update the table view itself
[[self responsesTableView] beginUpdates];
[[self responsesTableView] deleteRowsAtIndexPaths:[NSArray arrayWithObject:self.processingIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[[self responsesTableView] endUpdates];
答案 1 :(得分:1)
您是否在正确的数组上调用removeObjectAtIndex?根据错误消息,您实际上没有从tableview期望您从中删除的数据源中删除对象。我猜你可能正在从错误的数组中删除。
还有一件事要尝试:首先删除对象,然后执行deleteRowsAtIndexPath。
答案 2 :(得分:0)
您应该使用部分的方法
- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation;