Search code examples
objective-ccocoaexc-bad-accessviewdidloadsuper

EXC_BAD_ACCESS in viewDidLoad


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    @try {
        if ([segue.identifier isEqualToString:@"taskListSegue"])
        {   
            MindMapInformationViewController_iPhone *taskListContentController = [segue destinationViewController];  
            int selectedIndexPath = [[self.tableView indexPathForSelectedRow] row];

            MindMap *newMindMap;
            newMindMap = [mindmaps objectAtIndex:selectedIndexPath];        
            FileManager *fileManager = [[[FileManager alloc] init] autorelease];
            [fileManager readFile:newMindMap.pathToMindmapAtDevice parsing:YES];

            NSMutableArray *taskArray = [fileManager getArray];
            [taskListContentController setTasksOfSelectedMindmap:taskArray];
        }
    }
    @catch (NSException *exception) {

    }
}

-(void)setTasksOfSelectedMindmap:(NSMutableArray *)tasks {
    @try {
        [self initComponents];
        if (tasks != nil) {
            taskArray = tasks;
        }
    }
    @catch (NSException *exception) {

    }

}

-(void)initComponents {
    @try {
        taskArray = [[NSMutableArray  alloc] init];

        taskName = [[NSMutableArray alloc] init];
        taskOwner = [[NSMutableArray alloc] init];
    }
    @catch (NSException *exception) {

    }
}

-(void)viewDidLoad
{
    @try {
        [super viewDidLoad];
        int i = 0;
        for (MindMapTask *newTask in taskArray) {
            if (newTask.taskOwner == nil) {
                newTask.taskOwner = @"Keine Angabe";
            }
            [taskName addObject:newTask.taskTitle];
            [taskOwner addObject:newTask.taskOwner];

            i++;
        }

    }
    @catch (NSException *exception) {
        NSLog(@"Exception - %@", exception);
    }
}

Why I'm getting EXC_BAD_ACCESS? The producer of this exception seems to be [super viewDidLoad]; ...

Can anyone help me ? :)

EDIT: Changed the code a bit.. hope its understandable

You can see, that i moved the definiton of the arrays into an own method. I also added a method to make sure, that the taskTitle isn't nil (in an other class).


Solution

  • Try putting

    [super viewDidLoad];
    

    As the first statement.