Reputation: 805
I'm trying to delete the row from 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];
}
}
But I have an error
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).'
I'm update the DataSource self.forecastData, and it has 10 elements after deleting the row (11 at start). So, the number of elements is right. Where can be the problem ?
Upvotes: 1
Views: 1288
Reputation: 122391
Delete the data before telling the tableview:
[tempArray removeObjectAtIndex:1];
self.forecastsData = [tempArray copy];
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationFade];
Upvotes: 1