gpt4 book ai didi

objective-c - UIImage initWithContentsOfFile 不起作用

转载 作者:太空狗 更新时间:2023-10-30 03:21:34 25 4
gpt4 key购买 nike

我有问题:我想避免 [UIImage imageNamed:]。所以我做了:

UIImage *prodImg = [[UIImage alloc] initWithContentsOfFile:@"myimage.png"]; 
controller.productImg.image = prodImg;
[prodImg release];

但是现在图像不再显示了。

有人知道如何让它工作吗?

最佳答案

上面的代码不起作用,因为正确的方法是-

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

;)

关于objective-c - UIImage initWithContentsOfFile 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7525348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com