开发者

NSScrollView gives error when scrolling "-[CALayer isEqual:]: message sent to deallocated instance"

I'm trying to fix my code but I have no idea why I'm getting these errors:

modifying layer that is being finalized - 0x11818240
2010-09-10 02:35:53.022 iPhone Monkey Curling[1606:207] modifying layer that is being finalized - 0x11818240
2010-09-10 02:35:53.023 iPhone Monkey Curling[1606:207] modifying layer that is being finalized - 0x11818240
2010-09-10 02:35:54.671 iPhone Monkey Curling[1606:207] *** -[CALayer isEqual:]: message sent to deallocated instance 0x11818240

This happens when my all_score_table scroll view has had an attempt to scroll it (Crashes immediately on scroll attempt). Here is my code which sets the scroll views:

NSMutableArray * scores_data = [[first_data componentsSeparatedByString: @"\n"] mutableCopy];
        if ([scores_data count] != 3) {
            UIAlertView *connection_alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Malformed server response." delegate:nil cancelButtonTitle:@"Close" otherButtonTitles: nil];
            [connection_alert show];
            [connection_alert release];
            return;
        }
        if([[scores_data objectAtIndex:0] isEqual:@""]){
            [scores_data replaceObjectAtIndex:0 withObject:@"No scores for today,"];
        }
        if([[scores_data objectAtIndex:1] isEqual:@""]){
            [scores_data replaceObjectAtIndex:1 withObject:@"No scores this week,"];
        }
        if([[scores_data objectAtIndex:2] isEqual:@""]){
            [scores_data replaceObjectAtIndex:2 withObject:@"No scores,"];
        }
        [scores_data replaceObjectAtIndex:0 withObject: [[scores_data objectAtIndex:0] componentsSeparatedByString: @";"]];
        [scores_data replaceObjectAtIndex:1 withObject: [[scores_data objectAtIndex:1] componentsSeparatedByString: @";"]];
        [scores_data replaceObjectAt开发者_JS百科Index:2 withObject: [[scores_data objectAtIndex:2] componentsSeparatedByString: @";"]];
        NSLog(@"scores_data");
        if (todays_scores_table){
            //One of the tables exist so all of them must. Release them for renewal.
            [todays_scores_table release];
            [week_scores_table release];
            [all_scores_table release];
            [online_scores_pages release]; //release pages also
        }
        NSLog(@"1");
        todays_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 110, 295, 300)];
        week_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(330, 110, 295, 300)];
        all_scores_table = [[UIScrollView alloc] initWithFrame:CGRectMake(650, 110, 295, 300)];
        todays_scores_table.contentSize = CGSizeMake(205, 60 + 40*[[scores_data objectAtIndex:0] count]);
        week_scores_table.contentSize = CGSizeMake(205, 60 + 40*[[scores_data objectAtIndex:1] count]);
        all_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;
        UIImage * header_image;
        if(submission){
            path = [[NSBundle mainBundle] pathForResource: @"scores_header" ofType:@"png"];
            [data release];
            NSLog(@"3");
            data = [[NSData alloc] initWithContentsOfFile:path];
            header_image = [[UIImage alloc] initWithData:data];
        }
        UIImageView * header_view;
        int offset;
        UILabel * label;
        NSLog(@"4");
        UIScrollView * tables[3] = {todays_scores_table,week_scores_table,all_scores_table};
        online_scores_pages = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];
        online_scores_pages.contentSize = CGSizeMake(960, 420);
        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++) {
            if(submission){ //Only do header when submitting score
                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 %@ \n\n %@",score_data,scores_data);
                //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
            [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
            [online_scores_pages addSubview: tables[a]];
            [online_scores_pages addSubview: score_table_border];
            [score_table_border release];
        }
        [data release];
        if(submission){
            [header_image release];
            [header_view release];
        }
        [background_image release];
        [background_view release];
        [self addSubview: online_scores_pages];
        [online_scores_pages becomeFirstResponder];

Thank you for any help. It is much appreciated.


The only iEqual: that I see is in the series of tests:

if([[scores_data objectAtIndex:0] isEqual:@""]){ 
if([[scores_data objectAtIndex:1] isEqual:@""]){ 
if([[scores_data objectAtIndex:2] isEqual:@""]){

So looking back at scores_data I see:

MutableArray * scores_data = [[first_data componentsSeparatedByString: @"\n"] mutableCopy];

Is first_data a NSString? If so I'm suspecting that componentsSeparatedByString will return a array of strings. This means that when you do [scores_data objectAtIndex:?] you will get a string.

The isEqual: at this point then looks wrong. Instead of isEqual: you should probably use isEqualToString:.

However, you're seeing a problem with accessing a deallocated object. That implies an excessive number of releases and I can't see that here.

I don't like that call to "mutableCopy" that you are using. I'd prefer to be more explicit in the initialisation:

MutableArray * scores_data = [[NSMutableArray alloc] initWithArray:[first_data componentsSeparatedByString: @"\n"]];


Finally! I found the problem.

I had this call - [background_view release]; once to many. I remove it at the end as it was being released when necessary in the for loop.

Now it works!!!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜