質問

したがって、5つのUIImageViewを保持するために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プログラミングに精通していないので、誰かがここで手がかりをいただければ幸いです。ありがとう。

役に立ちましたか?

解決

Interface BuilderのビューにIBOutletsを配線しなかったため。おそらく img1 を配線したようですが、 img2 を配線しなかったため、 img2 nil であり、後でアウトレットが配線されている場合でも、 -initWithObjects:のオブジェクトのリストの最後。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top