gpt4 book ai didi

iphone - NSBundle——在一个包中寻找资源?

转载 作者:行者123 更新时间:2023-11-28 20:46:03 25 4
gpt4 key购买 nike

我在 bundle myBundle 中创建了一个目录 MyDirectory。然后我将图像 myImage.png 放入 MyDirectory 中。但是调用

 [myBundle pathForResource: @"myImage" ofType: @"png"] 

没有找到图像。我错过了什么?

编辑:澄清一下,如果图像位于包的顶层,它会发现它很好。

最佳答案

首先,您必须将图像添加到包中。如果您这样做了,我猜您会在将图像添加到项目时添加文件夹引用。如果是这样,您应该使用图像名称指定文件夹层次结构。

[myBundle pathForResource:@"MyDirectory/myImage" ofType:@"png"];

编辑:正如 Deepak 在下面评论的那样,还有更好的方法 pathForResource:ofType:inDirectory:

[myBundle pathForResource:@"myImage" ofType:@"png" inDirectory:@"MyDirectory"];

关于iphone - NSBundle——在一个包中寻找资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6316510/

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