gpt4 book ai didi

ios - NSInternalInconsistencyException uitableview

转载 作者:行者123 更新时间:2023-11-29 12:34:18 26 4
gpt4 key购买 nike

我正在尝试从 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).'

我正在更新数据源 self.forecastData,它在删除行后有 10 个元素(开始时有 11 个)。所以,元素的数量是正确的。问题出在哪里?

最佳答案

在告诉 TableView 之前删除数据:

[tempArray removeObjectAtIndex:1];
self.forecastsData = [tempArray copy];
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];

关于ios - NSInternalInconsistencyException uitableview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26782946/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com