2011-07-14 125 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'不保留,它的只是名字一个方法。不过,你说得对,使用它并不是一个好主意。 –