我正在尝试从UITableView中删除该行
-(void) closePickerViewRow:(id) sender {
if(self.pickerIsShown && [self.forecastsData count] > 0){
[self.tableView beginUpdates];
NSMutableArray* tempArray = [self.forecastsData mutableCopy];
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
[tempArray removeObjectAtIndex:1];
self.forecastsData = [tempArray copy];
[self.tableView endUpdates];
}
}
但我有错误
Terminating app due to 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 (11)
must be equal to the number of rows contained in that section before the
update(11),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).'
我正在更新DataSource self.forecastData,删除行后它有10个元素(开始时为11)。因此,元素的数量是正确的。哪里可以问题?
答案 0 :(得分:1)
在告诉tableview之前删除数据:
[tempArray removeObjectAtIndex:1];
self.forecastsData = [tempArray copy];
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];