Pergunta

Então, estou declarando um nsmutablearray para segurar 5 views uiimage.

.h Arquivo:

@interface ImageDisplay : UIViewController {
    IBOutlet UIImageView *img1;
    IBOutlet UIImageView *img2;
    IBOutlet UIImageView *img3;
    IBOutlet UIImageView *img4;
    IBOutlet UIImageView *img5;
    NSMutableArray *imageHolderArray;
}

@property (nonatomic, retain) IBOutlet UIImageView *img1;
@property (nonatomic, retain) IBOutlet UIImageView *img2;
@property (nonatomic, retain) IBOutlet UIImageView *img3;
@property (nonatomic, retain) IBOutlet UIImageView *img4;
@property (nonatomic, retain) IBOutlet UIImageView *img5;
@property (nonatomic, retain) IBOutlet NSMutableArray *imageHolderArray;
@end

No arquivo .m:

//All objects are synthesized, just easier not to crowd the screen

- (void)viewDidLoad {
    [super viewDidLoad];
    imageHolderArray = [[NSMutableArray alloc] initWithObjects: img1,img2,img3,img4,img5,nil];
    NSLog(@"imageHolderArray count: %i",[imageHolderArray count]); //Returns count of 1
}

Então, minha pergunta é: por que isso está acontecendo? Por que não está pegando todos os objetos da matriz? Não sou bem versado na programação Objective-C, então agradeço se alguém pudesse me indicar aqui. Obrigada.

Foi útil?

Solução

Porque você não ligou os iboutlets para suas opiniões no interface Builder. Parece que você provavelmente está conectado img1, mas não ligou img2, assim img2 é nil, que marca o fim de sua lista de objetos para -initWithObjects: Mesmo que as saídas posteriores sejam conectadas.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top