Folder in resources directory!
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.
精彩评论