Search code examples
ioscocos2d-iphoneuiimageresourcebundlensbundle

Oganization of Folders in XCode


I'm using physical folders to organise my files in XCode, as I have multiple files with the same name. Eg: /skin1/navbar.jpg and /skin2/navbar.jpg.

Every time I add a new file, I can't drag it into the folder, it seems like once I ad the folder as a group in XCode, it gets locked somehow and I can't change it. When I try to initialize a UIImage with this method, it turns out to be nil.

Using this image as an example: The path to the file

The full tree

To create a UIImage I'm using this:

    NSString *skinBasePath = [AppearanceUtils skinBasePath]; // Returns /Users/echilon/Library/Application Support/iPhone Simulator/5.1/Applications/E6C7ECF4-B36A-4092-97BC-CDE2D0A526C2/ReadMeAStory.app/ReadMeAStory/images/skin/wood/
    NSString *bgImagePath = [skinBasePath stringByAppendingPathComponent:@"button_181_43.png"],
             *bgImagePathPressed = [skinBasePath stringByAppendingPathComponent:@"button_181_43_pressed.png"];
    UIImage *bgImage = [UIImage imageWithContentsOfFile:bgImagePath]

Everything looks fine in the debugger until I actually create the image, which comes back as null.

The full path to the image in the debugger is /Users/echilon/Library/Application Support/iPhone Simulator/5.1/Applications/E6C7ECF4-B36A-4092-97BC-CDE2D0A526C2/ReadMeAStory.app/ReadMeAStory/images/skin/wood/button_181_43.png.

What am I missing?


Solution

  • "images" is just a Group and not a Folder, so .../ReadMeAStory.app/ReadMeAStory/images/ don't exist. What are you doing in [AppearanceUtils skinBasePath]?

    Maybe this will help: NSString *path=[[NSBundle mainBundle] pathForResource:@"button_181_43" ofType:@"png" inDirectory:@"skin/wood"];