繁体   English   中英

Xib之间的数据丢失

[英]Losing data between xibs

我试图将NSMutableArray的某些数据传递给另一个xib。 我创建了一个名为Gallery的NSObject类。 我在两个视图上都加载了它。

我正在加载填充NSMutableArray的XML。 然后,当我进入第一个视图时,它完美地填充了NSMutableArray,并在NSLog上给了我它的内容:

ProductPhotoGallery *telaGaleria = [[ProductPhotoGallery alloc] initWithNibName:@"ProductPhotoGallery" bundle:[NSBundle mainBundle]];

    Gallery *minhaGaleria = [[Gallery alloc] init];
    telaGaleria.galeria = minhaGaleria;
    telaGaleria.galeria.galeriaFotos =[[NSMutableArray alloc]init];

    TBXMLElement * nodeFotos = [TBXML childElementNamed:@"fotos" parentElement:rootXMLElement];

    TBXMLElement * nodeFoto = [TBXML childElementNamed:@"foto" parentElement:nodeFotos];

    while (nodeFoto) {

        NSString * urlFoto = [TBXML textForElement:nodeFoto];   
        [telaGaleria.galeria.galeriaFotos addObject:urlFoto];
        NSLog(@"%@", urlFoto);
        nodeFoto = [TBXML nextSiblingNamed:@"foto" searchFromElement:nodeFoto
                        ];
    }

    [telaGaleria release];

    NSLog(@"Array da Galeria %@", telaGaleria.galeria.galeriaFotos);

正确地给我,我加载另一个视图:

-(IBAction) vaiGaleria{

    ProductPhotoGallery *telaDaGaleria = [[ProductPhotoGallery alloc] initWithNibName:@"ProductPhotoGallery" bundle:[NSBundle mainBundle]];

    // Puxando a view

    [self.navigationController pushViewController:telaDaGaleria animated:YES];

    [telaDaGaleria release];


}

因此,当另一个视图出现时,我设置为在日志上显示数组:

- (void)viewDidLoad {

    self.galeria.galeriaFotos =[[NSMutableArray alloc]init];

    NSLog(@"ARRAY GALERIA DENTRO VIEW %@", self.galeria.galeriaFotos);

    [super viewDidLoad];
}

它给了我空值。 那么发生了什么?

谢谢!

viewDidLoad删除第一行,这将释放您先前分配的数组并分配一个新数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM