繁体   English   中英

NSInternalInconsistencyException异常uitableview

[英]NSInternalInconsistencyException uitableview

我正在尝试从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,在删除行(开始时为11)后,它具有10个元素。 因此,元素的数量是正确的。 问题出在哪里?

告诉表视图之前删除数据:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM