2011-07-14 169 views
1

我有這種情況下,我想從視圖中彈出並返回到原始視圖。
按下按鈕後,應用程序崩潰,控制檯顯示EXC_BAD_ACCESS。
我在儀器運行啓用了殭屍,這就是我得到:link to image
dealloc called twicedealloc調用兩次

,因爲它顯示的是dealloc的爲同一對象調用兩次。
儀器指向NSMutableArray其中包含NSStrings

任何人都可以幫我解決這個問題... 謝謝。

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:

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

你可以張貼一些代碼環繞數組的? –

+0

@Chris Gregg完成。 – astazed

+0

將代碼添加到您創建和釋放陣列的位置。特別是dealloc方法。 – Cyprian

回答

1

如果您創建的NSArray爲使用這些方法之一的自動釋放的對象,這可能發生:

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

還有然後在關閉UIViewController的dealloc方法中,您將釋放此數組。

編輯 順便說類詞reseverd它的壞像你這樣在這裏使用它:

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

不,這不是我創造我的數組的方式... ... – astazed

+0

改變字符串是如何被儲庫到stringWithFormat ... – astazed

+0

字'class'不保留,它的只是名字一個方法。不過,你說得對,使用它並不是一個好主意。 –