在我的应用程序中,我有很多图片分为几类(以下是项目和我的硬盘中的应用程序树):
ApplicationName
- Resources
-- Thumbs
-- Images
-- Buttons
-- Default.png
在 thumbs 文件夹中我有很多 .png 文件。问题是我想知道这个文件夹中有多少这些文件。我输入这样的命令:
NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Resources/Thumbs"];
而且它没有在 bundle 中找到任何文件。当我使用 inDirectory:@"."我得到了所有 .png 文件的列表(因此来自 Images,Buttons + Default),而我只需要这个目录。
我尝试通过两种方式将这些文件夹添加到项目中:1-“为任何添加的文件夹创建组”和 2-“为任何添加的文件夹创建文件夹引用”。
当我使用选项 1 inDirectory:@"Resources/Thumbs"];
时,它不起作用(namesArray 是 0 个对象)。为了测试,我尝试了 inDirectory:@"."],它的路径是:
/Users/name.surname/Library/Application Support/iPhone Simulator/4.3.2/Applications/applicationNumber/applicationName.app/0.png
当我在编译时使用选项 2 时,我在“附加到 applicationName...”处停止并且项目从未运行。
我如何知道我的 Thumbs 文件夹中有多少图像...?
最佳答案
我必须使用命令:
NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Thumbs/."];
并添加文件夹作为引用,然后一切正常^^。
关于objective-c - 捆绑 pathsForResourcesOfType :inDirectory:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7173648/