views:

163

answers:

2

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

A: 

I did it by retaining the UIImageView, and keeping a reference as an ivar, releasing on dealloc.

Gordon Fontenot
How would that help?
Nic Hubbard
I don't know why that would act any different than what you are doing, but that's exactly what I did to get this to work.
Gordon Fontenot
A: 
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.

Nic Hubbard