开发者

what is the proper way to set a UIImageView with a UIImage?

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"];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜