Получение сбоя с освобожденным объектом - PullRequest
0 голосов
/ 15 января 2012

Я получаю сбой с этим сообщением об ошибке: 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];
}

1 Ответ

0 голосов
/ 15 января 2012

В такой ситуации самый быстрый способ отследить преступника - включить NSZombies.Читайте здесь как это сделать.С включенными зомби ваша программа должна остановиться именно на той строке, которая вызывает сбой.

Я нашел хорошее руководство по устранению проблем с памятью на iOS здесь .

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...