UIImage initWithContentsOfFile 不起作用 [英] UIImage initWithContentsOfFile doesn't work
本文介绍了UIImage initWithContentsOfFile 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题:我想避免使用 [UIImage imageNamed:].所以我做到了:
I have question: I want to avoid [UIImage imageNamed:]. So i did:
UIImage *prodImg = [[UIImage alloc] initWithContentsOfFile:@"myimage.png"];
controller.productImg.image = prodImg;
[prodImg release];
但是现在图像不再显示了.
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];
;)
这篇关于UIImage initWithContentsOfFile 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文