开发者

UIImage initWithContentsOfFile doesn't work

开发者 https://www.devze.com 2023-04-07 02:45 出处:网络
I have question: I want to avoid [UIImage imageNamed:]. So i did: UIImage *prodImg = [[UIImage alloc] initWithContentsOfFile:@\"myimage.png\"];

I have question: I want to avoid [UIImage imageNamed:]. So i did:

UIImage *prodImg = [[UIImage alloc] initWithContentsOfFile:@"myimage.png"]; 
controller.productImg.image = prodImg;  
[prodImg re开发者_Go百科lease];

But now the image is not shown anymore.

Does anyone know how to get that to work?


The above code is not working because correct way to do it is-

NSString *thePath = [[NSBundle mainBundle] pathForResource:@"default" ofType:@"jpeg"];
UIImage *prodImg = [UIImage imageWithContentsOfFile:thePath]; 
controller.productImg.image = prodImg;  
[prodImg release];

;)

0

精彩评论

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

关注公众号