I have a UITableViewController managing a grouped tableView. The tableView is populated from a fetchedResultsController.
If I click the Edit button in the NavigationBar, then select a row and click the Delete button, the row is deleted and all ends well.
However, if I swipe to reveal the Delete button in a row and click the Delete button, the app crashes with the following error:
2010-01-06 15:25:18.720 Take10[14415:20b] Serious application error. Exception was caught during Core Data change processing: -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1) with userInfo (null)
2010-01-06 15:25:18.721 Take10[14415:20b] Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSCFArray objectAtIndex:]: index (1) beyond bounds (1)'
Of course, the index number in the error changes depending on the number of rows in the section where I am attempting to delete a row, and that number is 1 more than the number of remaining rows in the table section after the attempted delete.
Here is the code where I attempt to delete the data from the fetchedResultsController. The same method responds to both scenarios, so I don't understand why it crashes when swiping.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the managed object for the given index path
NSManagedObjectContext *context = [fetchedResultsController managedObjectContext];
[context deleteObject:[fetchedResultsController objectAtIndexPath:indexPath]];
// Save the context.
NSError *error = nil;
if (![context save:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
*/
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
Any ideas???
Thanks
Jk