2010-09-10 12 views
0

我試圖解決我的代碼,但我不知道爲什麼我得到這些錯誤:NSScrollView滾動時給出了錯誤「 - [CALayer的isEqual:方法]:消息發送到釋放實例」

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 

這發生在我的all_score_table滾動視圖嘗試滾動它時(滾動嘗試時立即崩潰)。這裏是我設置滾動視圖的代碼:

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 replaceObjectAtIndex: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]; 

謝謝你的幫助。非常感謝。

回答

0

終於來了!我發現了這個問題。

我有這個電話 - [background_view release];一次到很多次。我最後刪除它,因爲它在for循環中必要時被釋放。

現在,它的作品!

2

唯一iEqual:我看到的是在一系列的測試:

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

所以回頭看scores_data我看到:

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

是first_data一個的NSString?如果是這樣,我懷疑componentsSeparatedByString將返回一個字符串數組。這意味着當你做[scores_data objectAtIndex :?]時,你會得到一個字符串。

isEqual:此時看起來不對。而不是isEqual:你應該使用isEqualToString :.

但是,您看到訪問已釋放對象的問題。這意味着發佈數量過多,我在這裏看不到。

我不喜歡你正在使用的「mutableCopy」調用。我寧願要在初始化更加明確:

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

+0

謝謝。我加了你的建議,但我沒有接近解決問題。我向NSZombieEnabled添加了YES以接收這些錯誤以幫助我。如果無論如何要將由錯誤給出的內存地址鏈接回代碼?必須有一個方法來調試。 – 2010-09-10 13:55:47

相關問題