Objective c 为数组中的每个项添加单个UIImageView

Objective c 为数组中的每个项添加单个UIImageView,objective-c,ios,uiimageview,nsarray,Objective C,Ios,Uiimageview,Nsarray,我正在尝试为数组中的每个项目添加一个单独的UiImageView,这就是我目前所拥有的 _shapeArray = [NSArray arrayWithObjects:@"cloud.png",@"star.png", nil]; for (int i = 0; i < [_shapeArray count]; i++){ // I make a UIImage, which I will draw later UIImage* image = [

我正在尝试为数组中的每个项目添加一个单独的UiImageView,这就是我目前所拥有的

_shapeArray = [NSArray arrayWithObjects:@"cloud.png",@"star.png", nil];

    for (int i = 0; i < [_shapeArray count]; i++){
        // I make a UIImage, which I will draw later
        UIImage* image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",[_shapeArray objectAtIndex:i]]];

        UIImageView* blockView = [[UIImageView alloc] initWithImage:image];

        blockView.frame = CGRectMake(arc4random()%320, arc4random()%460, image.size.width, image.size.height);

        [self.view addSubview:blockView];

    }
\u shapeArray=[NSArray数组,其中包含对象:@“cloud.png”,“star.png”,nil];
对于(int i=0;i<[u shapeArray count];i++){
//我制作了一个UIImage,稍后我将绘制它
UIImage*image=[UIImage ImageName:[NSString stringWithFormat:@“%@,[\u ShaperRay objectAtIndex:i]];
UIImageView*blockView=[[UIImageView alloc]initWithImage:image];
blockView.frame=CGRectMake(arc4random()%320,arc4random()%460,image.size.width,image.size.height);
[self.view addSubview:blockView];
}

但正如您所知,它只添加了数组中的最后一个图像。我想不出一种方法可以将数组对象号添加到UIImageView的名称中。也许我走错了方向,如果是这样的话,最好的方法是什么?

这段代码很有效,但您需要确保以下几点:
-如果文件名实际存在于包中(检查大小写),则不会收到错误消息,但不会显示图片

-图像大小不要太大,并且不要相互覆盖

您正在将图像添加到同一帧中

   blockView.frame = CGRectMake(arc4random()%320+SomeXValue, arc4random()%460+SomeYvalue, image.size.width, image.size.height);

你得到了什么结果?两个图像视图,每个视图都带有star.png作为图像?没有一个UIImageView带有star图像。可能cloud.png不在您的包中。尝试删除图像,重新导入,选择“复制项目…”并在“添加到目标”中标记您的目标。好的,谢谢你,因为我在不同的iPad上试用过,效果很好。我已经在这上面呆了一段时间了。好的,下一个问题:我如何向它们添加触摸事件?