Delete NSManageObject at the event tableView:commiteEditingStyle:forRowAtIndexPath:

Posted by David.Chu.ca on Stack Overflow See other posts from Stack Overflow or by David.Chu.ca
Published on 2010-05-05T04:53:24Z Indexed on 2010/05/05 4:58 UTC
Read the original article Hit count: 226

Filed under:

I got exception when I tried to delete one NSManageObject at the event of tableView:commiteEditingStyle:forRowAtIndexPath:. Here is the part of my codes:

- (void)tableView:(..)tableView commitEditingStyle:(..)editingStyle 
  forRowAtIndexPath:(..)indexPath {
  if (editingStyle == UITableViewCellEditingStyleDelete) {
    [managedObjectContext deleteObject:
      [fetchedResultController objectAtIndexPath:indexPath]];
     ...
  }
}

The exception was thrown at the line of deleteObject:(method of my local NSManagedObjectContext). This is the exception message:

uncaught exception 'NSObjectInaccessibleException', reason: 'The NSManagedObject with ID:0x3d07a30 <x-coredata://0D2CC9CB-042B-496D-B3FE-5F1ED64EAB97/paymentType/p2> has been invalidated.'

I tried to get entity object first and then to delete it. The entity looks OK but still the exception was at delete:

 NSManagedObject *entityToDelete = 
    [fetchedResultsController objectAtIndexPath:indexPath];
 [mangedObjectContext deleteObject:entityToDelete]; // Exception again.

I am not sure if the entity object retrieved from the fetchedResultsController(NSFetchedResultsController type) cannot be deleted? If so, is there any other way to get the entity object for deleting?

© Stack Overflow or respective owner

Related posts about iphone