2012-01-14 84 views
0

我遇到了此错误消息:2012-01-14 15:09:36.667 [8274:15203] *** -[ExerciseHistoryDetailViewController controllerWillChangeContent:]: message sent to deallocated instance 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]; 
} 

编辑,我得到的应用程序再次崩溃与相同的工作流程,但调试输出略有不同。

这次的错误是:2012-01-14 17:35:48.793 [9012:15203] *** -[DetailViewController controllerWillChangeContent:]: message sent to deallocated instance 0x7fb6100

这是它坠毁在该行:(![managedObjectContext save:&error]) 这是方法:

-(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]; 
} 
+0

可能是这样的一个副本:http://stackoverflow.com/questions/6860064/controllerwillchangecontent-message-sent-to-deallocated-instance – jonkroll 2012-01-14 23:31:05

+0

那么,原因是,你(或系统,以你的名义)试图用已删除的对象执行'controllerWillChangeContent'。据推测这意味着你的NSFetchedResultsControllerDelegate实例被删除。可能是因为你发布了一个版本太多反对它。 – 2012-01-15 01:24:15

+0

我正在使用ARC,所以我没有发布任何东西...... – Jon 2012-01-15 01:34:19

回答

0

在这种情况下,以最快的方式追查元凶是启用NSZombies。阅读here如何做到这一点。启用僵尸后,您的程序应停止在导致崩溃的确切线路上。

我发现了一个很好的教程,介绍如何在iOS here上调试内存问题。

+0

我再次运行该应用程序,并将更新后的控制台输出置于问题中。 – Jon 2012-01-15 01:39:12