Deloloc звонил дважды

У меня есть этот случай, когда я хочу выскочить из вида и вернуться к исходному виду.
После нажатия кнопки приложение вылетает, и на консоли отображается EXC_BAD_ACCESS.
Я запускаю его на инструментах с включенными зомби, и вот что я получаю: ссылка на изображение
Deloloc звонил дважды

как показано, dealloc вызывается дважды для одного и того же объекта.
инструменты указывают на NSMutableArrayкоторый содержит NSStrings,

Может ли кто-нибудь помочь мне решить эту проблему... спасибо.

PS: решение, представленное в этом вопросе, не решает проблему.

Редактировать: массив заполнен данными, проанализированными из 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];
}

1 ответ

Это могло произойти, если вы создали NSArray как объект с автоматическим выпуском, используя один из этих методов:

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

А затем в методе dealloc вашего закрытия UIViewController вы освобождаете этот массив.

РЕДАКТИРОВАТЬ Между прочим, когда слово класса переиздано, плохо использовать его, как вы сделали здесь:

NSString *class=[[[NSString alloc] initWithFormat:@"%@",[(NSObject *)[listOfProperties objectAtIndex:i] class]] autorelease];
Другие вопросы по тегам