سؤال

لذلك أنا أعلن 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 إلى وجهات نظرهم في Builder Interface. يبدو أنك ربما تكون سلكيًا img1, ولكن لم يسلك img2, ، لذا img2 هو nil, الذي يمثل نهاية قائمة الكائنات الخاصة بك -initWithObjects: حتى لو كانت منافذ في وقت لاحق سلكية.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top