Objective c xcode 4设置了大量UIImageView';s

Objective c xcode 4设置了大量UIImageView';s,objective-c,xcode,Objective C,Xcode,我的视图中有8个UIImageView,都在.h和.m中声明 我叫他们img01,img02,img03,…,img08 我还有8张照片,分别是01.png,02.png,03.png,…,08.png 如果我想将第一张imageView设置为第一张图片,我将使用以下命令: UIImage *image = [UIImage imageNamed:@"01.png"]; [img01 setImage:image]; 如果我有很多UIImageView和图片怎么办 我试图使用这段代码,

我的视图中有8个UIImageView,都在
.h
.m
中声明

我叫他们
img01
img02
img03
,…,
img08

我还有8张照片,分别是
01.png
02.png
03.png
,…,
08.png

如果我想将第一张
imageView
设置为第一张图片,我将使用以下命令:

UIImage *image = [UIImage imageNamed:@"01.png"];
    [img01 setImage:image];
如果我有很多UIImageView和图片怎么办

我试图使用这段代码,但不知道如何执行最后一行代码

int count = 1;
while (count <= 8) {

    NSString *countString = [[NSString alloc]initWithFormat:@"%i", count];

    NSString *picname = [NSString stringWithFormat:@"0%@.png", countString];

    NSString *imgName = [NSString stringWithFormat:@"img0%@", countString];

    UIImage *image = [UIImage imageNamed:picname];

    [img01 setImage:image];

    count++;

}
int count=1;

而(count创建一个
NSMutableArray
,并用UIImageView填充它。目前您只设置了第一个:

[img01 setImage:image];
你可以这样做:

NSMutbaleArray imageViews = [[NSMutableArray alloc] initWithCapacity:8];
for (int i = 0; i < 8; ++i) {
    NSString *countString = [NSString stringWithFormat:@"%i", count];
    NSString *picname = [NSString stringWithFormat:@"0%@.png", countString];
    NSString *imgName = [NSString stringWithFormat:@"img0%@", countString];
    UIImage *image = [UIImage imageNamed:picname];
    UIImageView * view = [[[UIImageView alloc] init] autorelease];
    [view setImage:image];
    [imageViews addObject:view];
}
NSMutableArray imageViews=[[NSMutableArray alloc]initWithCapacity:8];
对于(int i=0;i<8;++i){
NSString*countString=[NSString stringWithFormat:@“%i”,count];
NSString*picname=[NSString stringWithFormat:@“0%@.png”,countString];
NSString*imgName=[NSString stringWithFormat:@“img0%@”,countString];
UIImage*image=[UIImage ImageName:picname];
UIImageView*视图=[[[UIImageView alloc]init]autorelease];
[查看设置图像:图像];
[图像视图添加对象:视图];
}

创建一个
NSMutableArray
,并用UIImageView填充它。目前您只设置了第一个:

[img01 setImage:image];
你可以这样做:

NSMutbaleArray imageViews = [[NSMutableArray alloc] initWithCapacity:8];
for (int i = 0; i < 8; ++i) {
    NSString *countString = [NSString stringWithFormat:@"%i", count];
    NSString *picname = [NSString stringWithFormat:@"0%@.png", countString];
    NSString *imgName = [NSString stringWithFormat:@"img0%@", countString];
    UIImage *image = [UIImage imageNamed:picname];
    UIImageView * view = [[[UIImageView alloc] init] autorelease];
    [view setImage:image];
    [imageViews addObject:view];
}
NSMutableArray imageViews=[[NSMutableArray alloc]initWithCapacity:8];
对于(int i=0;i<8;++i){
NSString*countString=[NSString stringWithFormat:@“%i”,count];
NSString*picname=[NSString stringWithFormat:@“0%@.png”,countString];
NSString*imgName=[NSString stringWithFormat:@“img0%@”,countString];
UIImage*image=[UIImage ImageName:picname];
UIImageView*视图=[[[UIImageView alloc]init]autorelease];
[查看设置图像:图像];
[图像视图添加对象:视图];
}

那怎么办?你能给我解释一下吗me@H.aLFaRSi-请参阅编辑,这是一个想法。由于我现在没有Mac电脑,因此未对其进行测试。尝试了您的代码并修复了许多错误,但仍然没有加载图像。请注意,此代码不加载视图,为此,您应循环数组并将其作为子视图添加。在代码above、 我创建了一个UIImageView数组,但我没有将它们添加到显示器中,为了向您演示如何操作,我首先需要多看一点您的代码。然后该怎么做?您能解释一下吗me@H.aLFaRSi-请参阅编辑,这是我的想法。由于我现在没有Mac电脑,所以未对其进行测试。我尝试了您的代码并修复了许多错误,但仍然没有Image是加载的注意,这段代码没有加载视图,要加载视图,你应该循环数组并将它们作为子视图添加。在上面的代码中,我创建了一个UIImageView数组,但我没有将它们添加到显示中,为了向你展示如何操作,我首先需要查看更多的代码。