views:

119

answers:

1

Hi, I'm supporting deleting rows in a UIView that includes a tableView:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
  [self.fetchedResultsController.managedObjectContext
            deleteObject:[self.fetchedResultsController
            objectAtIndexPath:indexPath]];
  NSError *error;
  if (![[self.fetchedResultsController managedObjectContext] save:&error]) {
   NSLog(@"Unresolved error %@, %@, %@", error, [error userInfo],
                    [error localizedDescription]);
  }
  else {NSLog(@"Apparently successful");}
  [self.tableView reloadData];
 }
}

When I try this out, I get the "Apparently successful" message in the console, but then a SIGABRT in configureCell. It's as though somewhere the object hasn't been deleted, and configureCell is trying to present a missing object. (When I re-run the app, though, the record is gone.)

Any thoughts? Thank you!

+2  A: 

You should not have that [self.tableView reloadData] there when using a NSFetchedResultsController.

When you delete an object, the right NSFetchedResultsControllerDelegate method will be called for you, where you should take care of updating your table view.

Create an empty Navigation-based Application and check the Use Core Data for Storage checkbox. What you will get is an empty project that does all this correct. It will be a good example.

St3fan
Hmm -- not sure about this. I removed [self.tableView reloadData] and the table did not update (row didn't disappear). When I closed the ViewController (a modal VC) and reopened it, I got the same SIGABRT. This is a ViewController that contains a UITableView as a property, implements <NSFetchedResultsControllerDelegate, UITableViewDataSource, UITableViewDelegate>.
ed94133
Show more code then. And a SIGABRT also comes with a stack trace that will probably give a good hint.
St3fan
If the table did not update then you are not implementing the delegate methods for the `NSFetchedResultsController` correctly. @St3fan is correct in his answer. Showing the full error would also be helpful.
Marcus S. Zarra
I finally had a chance to look at this more carefully, and you're correct, I hadn't implemented NSFetchedResultsControllerDelegate properly -- the Apple docs were helpful getting me there.
ed94133