I have a UIImageView that starts off with an image (loading.png) specified in IB. When my app starts, a new image is downloaded from the internet to replace the existing one. I do the following to replace the image:
if(object.imageView.image != nil){
[object.imageView.image release];
object.imageView.image = nil开发者_C百科;
}
object.imageView.image = [UIImage imageNamed:@"downloadedimage.png"];
Is this the right way to re-set an image? I am getting EXC_BAD_ACCESS when doing so.
UIImageView's image
property is declared as
@property(nonatomic, retain) UIImage *image;
That means when you set this property, the old value will be automatically -release
'd. So this 1 line is enough:
object.imageView.image = [UIImage imageNamed:@"downloadedimage.png"];
精彩评论