gpt4 book ai didi

iphone - 图片不会加载到UIImageView iPhone应用程序中

转载 作者:行者123 更新时间:2023-12-01 19:26:51 25 4
gpt4 key购买 nike

我试图仅在应用程序的首次启动时在UIImageView中显示图像。因此,在使用NSUserDefaults成功检测到此错误之后,我尝试在MainViewController中加载名为firstLaunch.png的图像。

我创建了UIImageView IBOutlet并进行了连接,并且一切正常,但是图像未加载。尽管稍后在代码中的其他地方,我仍可以成功更新UIImageView。这是我尝试将图像加载到UIImageView的行:

[countDownImage setImage:[UIImage imageWithContentsOfFile:@"firstLaunch.png"]];

最佳答案

您可以尝试获取文件的路径。
因此,假设图片在应用包中,请使用以下命令获取路径:

NSString *imgPath = [NSBundle mainBundle] pathForRessource:@"firstLaunch"
ofType:@"png"];
[countDownImage setImage:[UIImage imageWithContentsOfFile:imgPath]];

另一种方法是:
[countDownImage setImage:[UIImage imageNamed:@"firstLaunch.png"]];

关于iphone - 图片不会加载到UIImageView iPhone应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6808896/

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