Search code examples
iphoneobjective-cuinavigationcontrollerpushviewcontroller

why would this code crash with "attempt to access previously deallocated instance"?


Aren't i doing this the standard way? I see this format quite a bit and am not sure why my code eventually crashes and tells me I'm trying to access a previously deallocated instance.

Any help appreciated.

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {

    vcListGrades *listGradesViewController = [[vcListGrades alloc] initWithNibName:@"vcListGrades" bundle:nil];

    listGradesViewController.managedObjectContext = self.managedObjectContext;
    Course *sCourse = [_fetchedResultsController objectAtIndexPath:indexPath];
    [listGradesViewController setCourse: sCourse];

        [self.navigationController pushViewController:listGradesViewController animated:YES];   

    [listGradesViewController release];

}

Solution

  • Are you sure the problem is with your view controller, I would much likely say the problem is with sCourse, be sure of the memory management you do of the property course in your vcListGrades class. The management of the UIViewController seems to be just fine.