NSBundle-在捆绑中查找资源?

问题描述

| 我在捆绑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\"];
    ,        您是否将图像添加到Xcode项目(project.pbxproj)?     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...