iPhone uiimageview 배열
-
22-07-2019 - |
문제
그래서 나는 5 개의 uiimageviews를 보유하기 위해 nsmutablearray를 선언하고 있습니다.
.H 파일 :
@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
.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
}
그래서 내 질문은 왜 이런 일이 일어나고 있습니까? 왜 배열의 모든 객체를 선택하지 않습니까? 나는 Objective-C 프로그래밍에 정통하지 않으므로 누군가가 여기에 단서를 얻을 수 있다면 감사합니다. 고맙습니다.
해결책
Iboutlets를 인터페이스 빌더에서 뷰로 연결하지 않았기 때문입니다. 아마 당신이 유선 한 것 같습니다 img1
, 그러나 철화하지 않았습니다 img2
, 그래서 img2
~이다 nil
, 객체 목록의 끝을 표시합니다. -initWithObjects:
나중에 아울렛이 연결되어 있어도.
제휴하지 않습니다 StackOverflow