iPhone:向UIImageView添加UIImage会添加第二个图像

时间:2010-09-02 21:33:46

标签: iphone uiimageview uiimage

我有一个UIImageView,我已经将图像设置为。这工作正常,但后来,我想改变那个图像。因此,我为图像属性设置了一个新图像,但是当我查看应用程序时,该图像被设置为第一个图像:

UIImageView *image;
image = (UIImageView *)[cell viewWithTag:0];
image.image = [UIImage imageNamed:@"History_Row2.png"];

如何替换UIImageView中的当前图像而不是添加另一个?!

2 个答案:

答案 0 :(得分:0)

我是通过保留UIImageView并将引用保留为ivar,在dealloc上发布来实现的。

答案 1 :(得分:0)

image = (UIImageView *)[cell viewWithTag:0];

那是返回UITableViewCell而不是UIImageView,这是因为标签0是默认值,需要将其更改为其他数字。这样做之后就有效了。