问题描述
在我的应用程序中,我有很多图片,这些图片分为几类(以下是项目内部和HDD中的应用程序树):
In my application I have a lot of pictures divided into few categories (the following is an application tree inside a project and at my HDD):
ApplicationName
- Resources
-- Thumbs
-- Images
-- Buttons
-- Default.png
在thumbs文件夹中,我有很多.png文件.问题是我想知道此文件夹中有多少个这些文件.我输入这样的命令:
In the thumbs folder I have a lot of .png files. The problem is I want to know how many of these files are in this folder. I type such a command:
NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Resources/Thumbs"];
它在bundle中找不到任何文件.当我使用inDirectory:@时.我得到了所有.png文件的列表(因此来自Images,Buttons + Default),而我只需要一个目录.
And it doesn't find any files inside bundle. When I use inDirectory:@"." I get a list of all .png files (so from Images,Buttons + Default), while I need only this one catalog.
我已经尝试通过两种方式将这些文件夹添加到项目中:1-为任何添加的文件夹创建组"和2-为任何添加的文件夹创建文件夹引用".
I've tried to add these folders to project by two ways: 1-"Create groups for any added folder" and 2-"Create folder references for any added folders".
当我使用选项1 inDirectory:@"Resources/Thumbs"];
时,它不起作用(namesArray是0个对象).为了进行测试,我尝试了inDirectory:@."],结果该路径为:
When I use option 1, inDirectory:@"Resources/Thumbs"];
, it doesn't work (namesArray is 0 objects). To test, I tried inDirectory:@"."], and it went out that path is:
/Users/name.surname/Library/Application Support/iPhone Simulator/4.3.2/Applications/applicationNumber/applicationName.app/0.png
当我在编译时使用选项2时,我会停在附加到applicationName ...",并且该项目永远不会运行.
When I use option 2 while compiling I stop at "Attaching to applicationName..." and the project never runs.
我怎么知道我的Thumbs文件夹中有多少张图像...?
How do I know how many images I have in my Thumbs folder...?
推荐答案
我必须使用命令:
NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Thumbs/."];
并添加文件夹作为参考,然后一切正常,^^.
And add folders as a reference, everything worked then ^^.
这篇关于捆绑pathsForResourcesOfType:inDirectory:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!