iPhone的UIImageView阵列
-
22-07-2019 - |
题
所以我声明的NSMutableArray保持5周的UIImageViews。
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他们在Interface Builder的观点。看起来你很可能有线img1
,但没有电线img2
,所以img2
是nil
,这标志着你的,即使后来网点是有线-initWithObjects:
对象列表的末尾。
不隶属于 StackOverflow