2009-08-05 2 views
2

그래서 5 개의 UIImageViews를 보유하도록 NSMutableArray를 선언합니다.iPhone UIImageView Array

.H 파일 다음하는 .m 파일에서

@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 

:

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

그래서 제 질문은, 왜 이런 일이 있습니까? 배열의 모든 객체를 선택하지 않는 이유는 무엇입니까? 나는 Objective-C 프로그래밍에 정통하지 않으므로 누군가가 나를 여기에 실마리를 줄 수 있다면 고맙겠습니다. 고맙습니다.

+0

imgN 참조가 nil이 아닌 것이 확실합니까? – teabot

답변

2

인터페이스 빌더에서 IBOutlet을 뷰에 연결하지 않았기 때문에. img1이 유선 같지만 img2은 연결되어 있지 않으므로 img2nil입니다. 나중에 콘센트가 연결되어 있어도 -initWithObjects:에 대한 개체 목록의 끝을 표시합니다.

+0

와우, 네 말이 맞아, 고마워! –