开发者

Folder in resources directory!

开发者 https://www.devze.com 2023-02-25 02:37 出处:网络
I have a folder named \"test\" in my resources. I have a lot of images in there. How can I load all the images in the folder \"test\" in an array?

I have a folder named "test" in my resources. I have a lot of images in there. How can I load all the images in the folder "test" in an array?

I tried with:

开发者_开发问答
testArr = [[NSArray alloc] initWithArray:[[NSBundle mainBundle] pathsForResourcesOfType:@"gif" inDirectory:@"Test"]];

But it doesn't work!

Thx for your help!

greez franhu


pathsForResourcesOfType:inDirectory: gets you the filenames. Assuming you want the actual images, you might do:

NSArray *fileNames = [[NSBundle mainBundle] pathsForResourcesOfType:@"gif" inDirectory:@"Test"];
for(NSString *fileName in fileNames)
{
    // load the file here and put it in another array
}

Other things to check:

Open up your application bundle and verify that the Test directory exists in it.

If you're doing this on iOS, consider using [UIImage imageNamed:] instead, which will search your bundle for the image in question automatically.

0

精彩评论

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