NSString通过for loop进行编辑-iOS

NSString通过for loop进行编辑-iOS,ios,for-loop,uiimageview,int,Ios,For Loop,Uiimageview,Int,我有一个简单的for循环,它可以更改一组9个UIImageView中的图像。但是,我有一个问题,我无法更改UIImageView的名称来协调for循环,因此最终结果是for循环只影响iOS应用程序中9个UIImageView中的1个 这是我的密码: for (current_photo = 1; current_photo < 10; current_photo++) { picview_1.image = [UIImage imageNamed:[NSString str

我有一个简单的for循环,它可以更改一组9个UIImageView中的图像。但是,我有一个问题,我无法更改UIImageView的名称来协调for循环,因此最终结果是for循环只影响iOS应用程序中9个UIImageView中的1个

这是我的密码:

for (current_photo = 1; current_photo < 10; current_photo++) {
        picview_1.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@%i.png", SERVER_URL, current_photo]];
    }
当我将“picview\u 1”替换为“picview\u current\u photo”时,它会出现错误

我做错了什么?请解释一下


感谢您的时间:)

创建一个
UIImageView
s数组,并通过索引循环访问它们,如下所示:

NSArray *imageViews = @[picview_1, picview_2, picview_3, picview_4, ..., picview_9];
// Arrays are indexed from zero, so I changed the index to run from 0 to 9
for (current_photo = 0; current_photo < 9; current_photo++) {
    // Since current_photo is zero-based, I added one to it in stringWithFormat
    UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%@%i.png", SERVER_URL, current_photo+1]];
    [[imageViews objectAtIndex:current_photo] setImage:img];
}
NSArray*imageview=@[picview_1、picview_2、picview_3、picview_4、…、picview_9];
//数组从零开始索引,所以我将索引从0改为9
用于(当前照片=0;当前照片<9;当前照片++){
//因为当前的照片是零基的,所以我用stringWithFormat添加了一张
UIImage*img=[UIImage ImageName:[NSString stringWithFormat:@“%@%i.png”,服务器URL,当前照片+1];
[[imageViews objectAtIndex:current_photo]setImage:img];
}

您最好设置UIImageView数组。然后从该阵列访问所需的UIImageView,并根据需要设置图像。

谢谢。极好的解决方案。我还是一个初学者,所以我没有想到使用数组。
NSArray *imageViews = @[picview_1, picview_2, picview_3, picview_4, ..., picview_9];
// Arrays are indexed from zero, so I changed the index to run from 0 to 9
for (current_photo = 0; current_photo < 9; current_photo++) {
    // Since current_photo is zero-based, I added one to it in stringWithFormat
    UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%@%i.png", SERVER_URL, current_photo+1]];
    [[imageViews objectAtIndex:current_photo] setImage:img];
}