SHARE
TWEET

Untitled

a guest Aug 26th, 2013 27 Never
  1. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
  2.  
  3. if (editingStyle == UITableViewCellEditingStyleDelete) {
  4.     // Delete the managed object for the given index path
  5.     NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
  6.     [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
  7.  
  8.     // Save the context.
  9.     NSError *error = nil;
  10.     if (![context save:&error]) {
  11.         /*
  12.          Replace this implementation with code to handle the error appropriately.
  13.  
  14.          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.
  15.          */
  16.         NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
  17.         abort();
  18.     }
  19. }
  20.        
  21. - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
  22.    atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
  23.   newIndexPath:(NSIndexPath *)newIndexPath {
  24.  
  25. UITableView *tableView = self.tableView;
  26.  
  27. switch(type) {
  28.  
  29.     case NSFetchedResultsChangeInsert:
  30.         [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
  31.         break;
  32.  
  33.     case NSFetchedResultsChangeDelete:
  34.         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  35.         break;
  36.  
  37.     case NSFetchedResultsChangeUpdate:
  38.         [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
  39.         break;
  40.  
  41.     case NSFetchedResultsChangeMove:
  42.         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
  43.         [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade];
  44.         break;
  45. }
RAW Paste Data
Top