NSFetchedResultsController crash on -controllerDidChangeContent: in iPad

604 views Asked by At

NSFetchedResultsController crashes on -controllerDidChangeContent: on inserting new record and saving to persistentStore.

Code:

- (void)controller:(NSFetchedResultsController *)controller
   didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath
     forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath {
    NSLog(@"== UPDATING indexPath (%@) newIndexPath (%@) type %i", indexPath, newIndexPath, (int)type);
    switch (type) {
        case NSFetchedResultsChangeDelete: {
            [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
            break;
        }
        case NSFetchedResultsChangeInsert: {
            [self.tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationBottom];
            break;
        }
        case NSFetchedResultsChangeMove: {
            [self.tableView moveRowAtIndexPath:indexPath toIndexPath:newIndexPath];
            break;
        }
        case NSFetchedResultsChangeUpdate: {
            [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
            break;
        }
        default:
            break;
    }
}

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    NSLog(@"== BEGIN UPDATING");
    [self.tableView beginUpdates];
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    NSLog(@"== END UPDATING");
    [self.tableView endUpdates];
}

Note:- In target application FetchedResults delegate was implemented in UITableViewController subclass. And FetchedResultsController was working with child managed object context.

1

There are 1 answers

0
bteapot On

Possible sources of error (please provide an error message):

  1. MOC that provides data to FRC is not of NSMainQueueConcurrencyType.
  2. -controller:didChangeSection:atIndex:forChangeType: is not implemented.