Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 在阵列UIImageview中更新UIImage_Iphone_Objective C_Xcode - Fatal编程技术网

Iphone 在阵列UIImageview中更新UIImage

Iphone 在阵列UIImageview中更新UIImage,iphone,objective-c,xcode,Iphone,Objective C,Xcode,现在,我可以使用以下命令显示阵列中的UIImageView: [[self.guess objectAtIndex:1] setFrame:CGRectMake(20, 20, 100, 100)]; [self.view addSubview:[self.guess objectAtIndex:1]]; 如果要更改阵列中某个UIImageView中的图像 我可以使用: [self.guess replaceObjectAtIndex:1 withObject:Square]; 但我必须删除

现在,我可以使用以下命令显示阵列中的UIImageView:

[[self.guess objectAtIndex:1] setFrame:CGRectMake(20, 20, 100, 100)];
[self.view addSubview:[self.guess objectAtIndex:1]];
如果要更改阵列中某个UIImageView中的图像 我可以使用:

[self.guess replaceObjectAtIndex:1 withObject:Square];
但我必须删除原始视图,然后再次添加新的子视图:

[[self.guess objectAtIndex:1] removeFromSuperview];
[self.view addSubview:[self.guess objectAtIndex:1]];
问题是,我的新子视图没有继承帧位置和大小 原始图像(因为这可能已更改)。有办法做到这一点吗 更容易

我希望像这样的东西,只会更新原来的 相同位置、相同大小的图像:

[self.guess.image replaceObjectAtIndex:1 withObject:Square.image];

再次感谢

是否可以只存储阵列中的图像,而只存储一个UIImageView?然后,只要替换UIImageView元素中的图像就行了,如果您已经尝试过,我不知道,但这应该可以工作

UIImageView *img = (UIImageView *)[self.guess objectAtIndex:1];
img.image = Your Image;

Radu已经说过,最好保留一组图像或图像名称。然后,您也不必从superView中删除imageView,只需重新使用一个imageView即可

你留下的是这样的东西

yourImageView.image = [self.guess objectAtIndex:1];
如果只在数组中存储名称

yourImageView.image = [UIImage imageNamed:[self.guess objectAtIndex:1]];

我可以有一个视图并将图像存储在一个数组中,但我必须重写大量代码。我尝试了Brandons答案的一种变体:UIImageView*test=[self.guess objectAtIndex:1];self.Square.frame=test.frame;这似乎解决了我的问题,尽管它仍然冗长!谢谢