How to load images from a specific group?

2019-06-09 22:28发布

问题:

In Xcode4, I use groups for grouping my stuff, for example I have a tree like group hierarchy for my various images. The interesting part is that I can access an image directly without specifying a group.

UIImage *img = [UIImage imageWithName:@"image1.png"];

I have two questions. First, how to define concrete path of groups where resides all needed images (for example for the group tree "Img/Enemy/")? And a second, how to iterate through that group path to load all the images from that group? IMHO groups are related to bundles but I found them very confusing :(

回答1:

When you use groups, you are not actually creating folders, so when you build your app everything is put at the root of the bundle. This is why you can access them without specifying the group name. If you want to use folders, you can create folders in Finder and add them to the project (make sure to check "create folder references for any added folders"!).



回答2:

Groups are only used to organize file within Xcode; they are not really of any use outside of Xcode, nor does Xcode copy them over to the final app.

You need to use folder references instead of groups to do what you want.