views:

705

answers:

1

So I'm declaring a NSMutableArray to hold 5 UIImageViews.

.h file:

@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

In the .m file:

//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
}

So my question is, why is this happening? Why isn't it picking up all the objects in the Array? I'm not well versed in Objective-C programming so I'd appreciate it if someone could clue me in here. Thank you.

+2  A: 

Because you didn't wire the IBOutlets to their views in Interface Builder. Looks like you probably wired img1, but didn't wire img2, so img2 is nil, which marks the end of your list of objects for -initWithObjects: even if later outlets are wired.

Rob Napier
Wow you're exactly right, thank you!