Error:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[__NSCFArray removeObjectAtIndex:]: mutating method sent to immutable object'
The code:
.h
@property (nonatomic, strong) NSMutableArray *history;
.m
- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSString *de = [[self.history objectAtIndex:indexPath.row] objectForKey:@"des"];
NSString *dest = [de stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *jsonURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://example.com/rm_history.php?user_id=%@&destinations=%@",self.uID,dest]];
NSData *jsonData = [NSData dataWithContentsOfURL:jsonURL];
[self.history removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil]
withRowAnimation:UITableViewRowAnimationFade];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
NSLog(@"create");
}
[self.tableView reloadData];
}
After setting a breakpoint to catch the error, it stops at this line:
[self.history removeObjectAtIndex:indexPath.row]
Any idea on what is causing the problem?
source
share