开发者

Bundle pathsForResourcesOfType:inDirectory:

开发者 https://www.devze.com 2023-03-30 14:47 出处:网络
In my application I have a lot of pictures divided into few categories (the follow开发者_如何学JAVAing is an application tree inside a project and at my HDD):

In my application I have a lot of pictures divided into few categories (the follow开发者_如何学JAVAing is an application tree inside a project and at my HDD):

ApplicationName
- Resources
-- Thumbs
-- Images
-- Buttons
-- Default.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"];

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.

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".

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

When I use option 2 while compiling I stop at "Attaching to applicationName..." and the project never runs.

How do I know how many images I have in my Thumbs folder...?


I had to use command:

NSArray *namesArray = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Thumbs/."];

And add folders as a reference, everything worked then ^^.


NSArray *array = [[NSBundle mainBundle] pathsForResourcesOfType:@".png" inDirectory:@"Thumbs"];

To use this function, you need to declare your folder like this (When you drag the folder into your bundle):

Bundle pathsForResourcesOfType:inDirectory:

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号