开发者

iPhone: Adding UIImage to UIImageView adds a second image

开发者 https://www.devze.com 2023-01-14 01:11 出处:网络
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 se

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?!


I did it by retaining the UIImageView, and keeping a reference as an ivar, releasing on 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消