views:

11

answers:

0

Hello. In my program I have this code:

@try{
    if (online_scores_pages != nil){
        NSLog(@"Here - %@",online_scores_pages);
    }else{
        NSLog(@"NIL");
    }
    [online_scores_pages removeFromSuperview];
    NSLog(@"Here 2");
    [self becomeFirstResponder];
    NSLog(@"Here 3");
    section = CURLING_MENU;
    }@catch (NSException * e) {
        NSLog(@"%@",[e reason]);
    }

It outputs:

2010-09-07 20:29:35.543 iPhone Monkey Curling[1071:207] Here - <UIScrollView: 0x5ef5920; frame = (0 0; 320 420); clipsToBounds = YES; layer = <CALayer: 0x5ef5850>; contentOffset: {0, 0}>
Program received signal:  “EXC_BAD_ACCESS”.

No exceptions raised of-course.

Not only that, the scroll view will crash the program when the user scrolls past the righthand side. No idea why this is. I'm sure the code used to initialise the scrollview and pack it with contents will give clues:

NSMutableArray * scores_data = [[[response substringFromIndex: 1] componentsSeparatedByString: @"\n"] mutableCopy];
                    [scores_data replaceObjectAtIndex:0 withObject: [[scores_data objectAtIndex:0] componentsSeparatedByString: @";"]];
                    [scores_data replaceObjectAtIndex:1 withObject: [[scores_data objectAtIndex:1] componentsSeparatedByString: @";"]];
                    [scores_data replaceObjectAtIndex:2 withObject: [[scores_data objectAtIndex:2] componentsSeparatedByString: @";"]];
                    NSLog(@"scores_data");
                    if (ogl_view->todays_scores_table){
                        //One of the tables exist so all of them must. Release them for renewal.
                        [ogl_view->todays_scores_table release];
                        [ogl_view->week_scores_table release];
                        [ogl_view->all_scores_table release];
                        [ogl_view->online_scores_pages release]; //release pages also
                    }
                    NSLog(@"1");
                    ogl_view->todays_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 110, 295, 300)];
                    ogl_view->week_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(330, 110, 295, 300)];
                    ogl_view->all_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(650, 110, 295, 300)];
                    ogl_view->todays_scores_table.contentSize = CGSizeMake(205, 60 + 40*[[scores_data objectAtIndex:0] count]);
                    ogl_view->week_scores_table.contentSize = CGSizeMake(205, 60 + 40*[[scores_data objectAtIndex:1] count]);
                    ogl_view->week_scores_table.contentSize = CGSizeMake(205, 60 + 40*[[scores_data objectAtIndex:2] count]);
                    NSLog(@"2");
                    NSArray * score_data;
                    NSString * path = [[NSBundle mainBundle] pathForResource: @"single_score_image" ofType:@"png"];
                    NSData * data = [[NSData alloc] initWithContentsOfFile:path];
                    UIImage * background_image = [[UIImage alloc] initWithData:data];
                    UIImageView * background_view;
                    path = [[NSBundle mainBundle] pathForResource: @"scores_header" ofType:@"png"];
                    [data release];
                    NSLog(@"3");
                    data = [[NSData alloc] initWithContentsOfFile:path];
                    UIImage * header_image = [[UIImage alloc] initWithData:data];
                    UIImageView * header_view;
                    int offset;
                    UILabel * label;
                    NSLog(@"4");
                    UIScrollView * tables[3] = {ogl_view->todays_scores_table,ogl_view->week_scores_table,ogl_view->all_scores_table};
                    ogl_view->online_scores_pages = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
                    ogl_view->online_scores_pages.contentSize = CGSizeMake(960, 420);
                    ogl_view->online_scores_pages.pagingEnabled = YES; //Act like iphone home page
                    UIImage * title_image;
                    UIImageView * title_view;
                    NSLog(@"5");
                    //border for scores table
                    [data release];
                    path = [[NSBundle mainBundle] pathForResource: @"score_table_border" ofType:@"png"];
                    data = [[NSData alloc] initWithContentsOfFile:path];
                    UIImage * border_image = [[[UIImage alloc] initWithData:data] autorelease];
                    UIImageView * score_table_border;
                    for (int a = 0; a < 3; a++) {
                        header_view = [[UIImageView alloc] initWithImage: header_image];
                        header_view.frame = CGRectMake(10, 10, 275, 30);
                        NSLog(@"5A");
                        [tables[a] addSubview: header_view];
                        [header_view release];
                        label = [[UILabel alloc] initWithFrame:CGRectMake(25, 10, 245, 30)];
                        label.backgroundColor = [UIColor clearColor];
                        NSLog(@"5B");
                        NSString * end;
                        NSLog(@"5C");
                        if ([[scores_data objectAtIndex:a+3] characterAtIndex:0] == '1'){
                            end = @"st";
                        }else if ([[scores_data objectAtIndex:a+3] characterAtIndex:0] == '2'){
                            end = @"nd";
                        }else if ([[scores_data objectAtIndex:a+3] characterAtIndex:0] == '3'){
                            end = @"rd";
                        }else{
                            end = @"th";
                        }
                        NSArray * pos_data = [[scores_data objectAtIndex:a+3] componentsSeparatedByString: @"/"];
                        label.text = [NSString stringWithFormat: @"You came %@%@ from %@ scores.",[pos_data objectAtIndex:0],end,[pos_data objectAtIndex:1]];
                        [tables[a] addSubview:label];
                        NSLog(@"5E");
                        [label release];
                        NSLog(@"6");
                        for (int x = 0; x < [[scores_data objectAtIndex:a] count]; x++){
                            score_data = [[[scores_data objectAtIndex:a] objectAtIndex:x] componentsSeparatedByString: @","];
                            //Image for each score
                            offset = 50 + 40*x;
                            background_view = [[UIImageView alloc] initWithImage: background_image];
                            background_view.frame = CGRectMake(10, offset, 275, 30); //Reposition
                            [tables[a] addSubview: background_view];
                            [background_view release];
                            //Add score position
                            label = [[UILabel alloc] initWithFrame:CGRectMake(10, offset, 30, 30)];
                            label.backgroundColor = [UIColor clearColor];
                            label.text = [NSString stringWithFormat: @"%i",x+1];
                            label.textAlignment = UITextAlignmentCenter;
                            [tables[a] addSubview:label];
                            [label release];
                            NSLog(@"7");
                            //Add name
                            label = [[UILabel alloc] initWithFrame:CGRectMake(55, offset, 190, 30)];
                            label.backgroundColor = [UIColor clearColor];
                            label.text = [score_data objectAtIndex:0];
                            [tables[a] addSubview:label];
                            [label release];
                            //Add score
                            label = [[UILabel alloc] initWithFrame:CGRectMake(55, offset, 225, 30)];
                            label.backgroundColor = [UIColor clearColor];
                            label.text = [NSString stringWithFormat: @"%@",[score_data objectAtIndex:1]];
                            label.textAlignment = UITextAlignmentRight;
                            [tables[a] addSubview:label];
                            [label release];
                            NSLog(@"8");
                        }
                        //Add title
                        switch (a) {
                            case 0:
                                path = [[NSBundle mainBundle] pathForResource: @"todays_scores_title" ofType:@"png"];
                                break;
                            case 1:
                                path = [[NSBundle mainBundle] pathForResource: @"week_scores_title" ofType:@"png"];
                                break;
                            case 2:
                                path = [[NSBundle mainBundle] pathForResource: @"all_scores_title" ofType:@"png"];
                                break;
                        }
                        [data release];
                        data = [[NSData alloc] initWithContentsOfFile:path];
                        title_image = [[[UIImage alloc] initWithData:data] autorelease];
                        title_view = [[[UIImageView alloc] initWithImage: title_image] autorelease];
                        title_view.frame = CGRectMake(25 + 320*a, 15, 270, 75); //Reposition and resize
                        [ogl_view->online_scores_pages addSubview:title_view];
                        NSLog(@"9");
                        //Add table
                        score_table_border = [[UIImageView alloc] initWithImage: border_image];
                        score_table_border.frame = CGRectMake(320*a, 100, 320, 320); //Reposition
                        [ogl_view->online_scores_pages addSubview: tables[a]];
                        [ogl_view->online_scores_pages addSubview: score_table_border];
                        [score_table_border release];
                    }
                    [data release];
                    [header_image release];
                    [header_view release];
                    [background_image release];
                    [background_view release];
                    [ogl_view addSubview: ogl_view->online_scores_pages];
                    [ogl_view->online_scores_pages becomeFirstResponder];

Sorry because that's a lot of code but all of it is relevant to the creation of that scroll view.

If anyone can help me here I will be very happy and I will thank you very much. It's slightly annoying when a problem is simply too weird for me to debug myself.