我不确定这是预期还是错误.我试图在磁盘中创建与XCode相同的文件夹结构.我使用以下步骤将资源文件添加到我的项目:
Resources在项目的根文件夹下创建一个文件夹.Resources文件夹拖到XCode,Group为该文件夹创建一个.Finder的Resources文件夹.现在我可以看到Build Phrases- > 中列出了所有资源文件Copy Bundle Resources.
奇怪的是[[NSBundle mainBundle] pathForResource:@"book" ofType:@"epub"]返回一个可以定位的文件路径,同时[[NSBundle mainBundle] pathForResource:@"book" ofType:@"epub" inDirectory:@"Resources"]返回(null).
从Build Results窗口,我注意到这一行:
CpResource MBookReader/Resources/book.epub /Users/neevek/Library/Developer/Xcode/DerivedData/workspace-fykuaikryknuhxgevcdtspkspptj/Build/Products/Debug-iphonesimulator/MBookReader.app/book.epub
cd /Users/neevek/workspace/xcode_projects/MBookReader
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
builtin-copy -exclude .DS_Store -exclude CVS -exclude .svn -exclude .git -exclude .hg -resolve-src-symlinks -strip-tool /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip /Users/neevek/workspace/xcode_projects/MBookReader/MBookReader/Resources/book.epub /Users/neevek/Library/Developer/Xcode/DerivedData/workspace-fykuaikryknuhxgevcdtspkspptj/Build/Products/Debug-iphonesimulator/MBookReader.app
Run Code Online (Sandbox Code Playgroud)
这表明Resources/book.epub文件确实被复制到MBookReader.app/(应用程序包的根目录).
现在Resources是磁盘中的真实文件夹,为什么不复制文件夹本身?
PS.我正在使用XCode 4.3.2.
我的图像资源目录有一个名为"自然"的文件夹,里面有数百个图像文件.
我想在我的图像资源中的"自然"目录下获得一组图像文件名.然后,我将从该数组中选择一个随机图像名称并显示它[UIImage imageNamed:@"..."].我被困在如何在'IncludedStudyImages'目录下获取一系列图像名称.我甚至无法在文档中找到有关如何以编程方式与我的图像资源交互的任何内容(除了显示它们).
谢谢你的帮助.