简体   繁体   English

尝试循环遍历图像并将其添加到数组中

[英]Trying to loop through images and add them to array

I'm trying to loop through my mutable array and add image objects 3-81. 我正在尝试遍历我的可变数组并添加图像对象3-81。 Heres my code. 继承我的代码。 Can someone tell me why its not working? 有人可以告诉我为什么它不起作用?

- (instancetype)init {
    self = [super init];
    if (self) {
        self.imageData = [NSMutableArray arrayWithObjects:[UIImage imageNamed:@"image1.gif"],       [UIImage imageNamed:@"image2.gif"],  nil];

        for (int i = 3; i <= 81; i++) {
            NSString *imageName = [NSString stringWithFormat:@"image%i", i];
            [self.imageData addObject:[UIImage imageNamed:imageName]];
        }
    }
    return self;
}

You are adding images named "image1.gif" and "image2.gif". 您正在添加名为“image1.gif”和“image2.gif”的图像。 However, in your loop you are adding images named "image3", "image4", "image5", etc. The missing ".gif" is likely the problem. 但是,在循环中,您要添加名为“image3”,“image4”,“image5”等的图像。缺少“.gif”可能是问题所在。

NSString *imageName = [NSString stringWithFormat:@"image%i.gif", i];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM