【问题标题】:iPhone UIImageView ArrayiPhone UIImageView 数组
【发布时间】:2010-11-17 03:17:36
【问题描述】:

所以我声明一个 NSMutableArray 来保存 5 个 UIImageView。

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

所以我的问题是,为什么会这样?为什么它不拾取 Array 中的所有对象?我不精通Objective-C编程,所以如果有人能在此处提示我,我将不胜感激。谢谢。

【问题讨论】:

  • 你确定没有一个 imgN 引用是 nil 吗?

标签: iphone uiimageview nsarray


【解决方案1】:

因为您没有将 IBOutlets 连接到它们在 Interface Builder 中的视图。看起来您可能连接了img1,但没有连接img2,所以img2nil,这标志着-initWithObjects: 的对象列表的结尾,即使后来的插座已连接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    相关资源
    最近更新 更多