Iphone 使用解除分配的对象获取崩溃

Iphone 使用解除分配的对象获取崩溃,iphone,objective-c,cocoa-touch,Iphone,Objective C,Cocoa Touch,我收到的错误消息导致崩溃:2012-01-14 15:09:36.667[8274:15203]***-[ExerciseHistoryDetailViewController-controllerWillChangeContent:]:消息发送到解除分配的实例0x8d0e1f0 这是代码。知道是什么引起的吗 - (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { [self.histo

我收到的错误消息导致崩溃:
2012-01-14 15:09:36.667[8274:15203]***-[ExerciseHistoryDetailViewController-controllerWillChangeContent:]:消息发送到解除分配的实例0x8d0e1f0

这是代码。知道是什么引起的吗

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
    [self.historyTableView beginUpdates];
}

- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
           atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type {
    switch(type) {
        case NSFetchedResultsChangeInsert:
            [self.historyTableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
        case NSFetchedResultsChangeDelete:
            [self.historyTableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}

- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
       atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
      newIndexPath:(NSIndexPath *)newIndexPath {
    UITableView *tableView = self.historyTableView;

    switch(type) {
        case NSFetchedResultsChangeInsert:
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;
        case NSFetchedResultsChangeDelete:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            break;
        case NSFetchedResultsChangeUpdate:
            [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
            break;
        case NSFetchedResultsChangeMove:
            [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade];
            break;
    }
}

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
    [self.historyTableView endUpdates];
}

在这种情况下,追踪罪犯的最快方法是启用NSZombies。阅读如何做。启用僵尸后,您的程序应在导致崩溃的确切线路上停止


我找到了一个很好的关于如何在iOS上调试内存问题的教程。

可能与此重复:原因是您(或代表您的系统)试图使用删除的对象执行
controllerWillChangeContent
。这可能意味着您的NSFetchedResultsControllerDelegate实例已被删除。可能是因为你发布的版本太多了。我正在使用ARC,所以我不会发布任何东西…@jonkroll这个问题的答案解决了我的崩溃。谢谢。我再次运行了应用程序,并将更新的控制台输出放入问题中。
-(IBAction)createSet
{    
    Set *set = (Set *)[NSEntityDescription insertNewObjectForEntityForName:@"Set" inManagedObjectContext:managedObjectContext];
    [self.exercise addSetsObject:set];

    NSError *error = nil;
    if (![managedObjectContext save:&error]) 
    {
        // Handle the error.
    }
    NSLog(@"error: %@", error);
    [self checkIfEmpty];
    self.fetchedResultsController = nil; 
    [setsTableView reloadData];
}