简体   繁体   中英

iPhone: Adding UIImage to UIImageView adds a second image

I have a UIImageView that I have already set an image to. This works fine, but later, I want to change that image. So, I set a new image for the image property, but when I view the app, that image is set as a second image over the first:

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

How can I replace the current image in my UIImageView rather than seeming to add another?!

我通过保留UIImageView并保持引用为ivar并在dealloc上释放来做到这一点。

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

That was returning a UITableViewCell rather than a UIImageView, this is because the tag 0 is the default and it needs to be changed to a different number. After doing this it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM