2011-07-14 21 views
1

私はビューからポップして元のビューに戻るこのケースがあります。
ボタンを押すとアプリがクラッシュし、コンソールにEXC_BAD_ACCESSが表示されます。ゾンビを有効にして
私は楽器でそれを実行し、これは私が得るものです:それはのdeallocを示されているよう
dealloc called twicedeallocが2回呼び出されました

link to imageは、同じオブジェクトに対して2回呼び出され。
機器は、NSStringsを含むNSMutableArrayを指しています。

誰でもこの問題を解決するのに役立つことができます... ありがとうございます。

ps:解決策がthis questionで提供されても問題は解決しません。

編集: この配列は、xmlファイルから解析されたデータで埋められます。

-(void) grabData{ 
    listOfNames=[[NSMutableArray alloc] init]; 


    NSString *XMLPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"chi.xml"]; 
    NSData *XMLData = [NSData dataWithContentsOfFile:XMLPath]; 
    CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithData:XMLData options:0 error:nil] autorelease]; 

    NSArray *items = [rssParser nodesForXPath:@"/template/item" error:nil]; 
    for (CXMLElement *node in items) { 
     int counter; 
     if([[[node attributeForName:@"type"] stringValue] isEqualToString:@"label"]){ 
      for(counter = 0; counter < [node childCount]; counter++) { 
       [listOfNames addObject:[[node childAtIndex:counter] stringValue]]; 
      } 
     } 
... 

と、この機能で使用されています

-(void)setupPage{ 
    [scroll setCanCancelContentTouches:NO]; 
    scroll.indicatorStyle=UIScrollViewIndicatorStyleWhite; 
    scroll.clipsToBounds=YES; 
    scroll.scrollEnabled=YES; 
    scroll.pagingEnabled=NO; 
    int y=Y; 
    CGFloat cy=0; 
    int count=[listOfProperties count]; 
    int total=count; 
    for(int i=0;i<count;i++){ 
     NSString *class=[[[NSString alloc] initWithFormat:@"%@",[(NSObject *)[listOfProperties objectAtIndex:i] class]] autorelease]; 
     if([class isEqualToString:@"textFieldCell"]){ 
      ((textFieldCell*)[listOfProperties objectAtIndex:i]).str=[listOfNames objectAtIndex:i]; 
      [((textFieldCell*)[listOfProperties objectAtIndex:i]) setTarget:scroll]; 
      ((textFieldCell*)[listOfProperties objectAtIndex:i]).view.frame=CGRectMake(X,y,self.view.frame.size.width - remProfX,cellProfH); 
      [((textFieldCell*)[listOfProperties objectAtIndex:i]) setImage:[self getImageName:i maxValue:(count-1)]]; 
      [scroll addSubview:((textFieldCell*)[listOfProperties objectAtIndex:i]).view]; 
     } 
     else{ 
      if([class isEqualToString:@"comboBoxCell"]){ 
       ((comboBoxCell*)[listOfProperties objectAtIndex:i]).str=[listOfNames objectAtIndex:i]; 
       [((comboBoxCell*)[listOfProperties objectAtIndex:i]) setTarget:self.view]; 
       ((comboBoxCell*)[listOfProperties objectAtIndex:i]).view.frame=CGRectMake(X,y,self.view.frame.size.width - remProfX,cellProfH); 
       [((comboBoxCell*)[listOfProperties objectAtIndex:i]) setImage:[self getImageName:i maxValue:(count-1)]]; 
       [scroll addSubview:((comboBoxCell*)[listOfProperties objectAtIndex:i]).view]; 
      } 
      else{ 
       if([class isEqualToString:@"dateCell"]){ 
        ((dateCell*)[listOfProperties objectAtIndex:i]).str=[listOfNames objectAtIndex:i]; 
        [((dateCell*)[listOfProperties objectAtIndex:i]) setTarget:self.view]; 
        ((dateCell*)[listOfProperties objectAtIndex:i]).view.frame=CGRectMake(X,y,self.view.frame.size.width - remProfX,cellProfH); 
        [((dateCell*)[listOfProperties objectAtIndex:i]) setImage:[self getImageName:i maxValue:(count-1)]]; 
        [scroll addSubview:((dateCell*)[listOfProperties objectAtIndex:i]).view]; 
       } 
      } 
... 

にdealloc:あなたがそれらのいずれかの方法を使用して、自動解放オブジェクトとしてあなたにNSArrayを作成した場合、これが起こっている可能性があります

- (void)dealloc { 
    [listOfNames release]; 
    [listOfProperties release]; 
    [listOfGroupNames release]; 
    [listOfCheckBoxNames release]; 
    [listOfCheckBoxes release]; 
    [listOfButtons release]; 
    [scroll release]; 
    [super dealloc]; 
} 
+4

あなたは、配列を囲むあなたのコードの一部を投稿することができます:クラスワードは、それはあなたがここでやったようにそれを使用することが悪いですreseverdれるところで

EDIT ? –

+0

@Chris Gregg done。 – astazed

+0

配列を作成してリリースするコードを追加します。特にdeallocメソッド。 – Cyprian

答えて

1

+ array 
+ arrayWithArray: 
+ arrayWithContentsOfFile: 
+ arrayWithContentsOfURL: 
+ arrayWithObject: 
+ arrayWithObjects: 
+ arrayWithObjects:count: 

そして、閉じたUIViewControllerのdeallocメソッドでこの配列を解放します。

NSString *class=[[[NSString alloc] initWithFormat:@"%@",[(NSObject *)[listOfProperties objectAtIndex:i] class]] autorelease]; 
+0

これは私の配列を作成する方法ではありません... – astazed

+0

文字列がstringWithFormatにリセバリされる方法を変更しました... – astazed

+0

単語 'class'は予約されていません、それはちょうど名前です方法。あなたはそれを使うのは良い考えではないと思っています。 –

関連する問題