2012-08-27 78 views
2

我使用物理文件夹来组织XCode中的文件,因为我有多个具有相同名称的文件。例如:/skin1/navbar.jpg和/skin2/navbar.jpg。组织XCode中的文件夹

每次我添加一个新文件时,我都无法将它拖入文件夹,好像我一旦在XCode中将文件夹作为一个组添加到文件夹中,它就会被锁定,我无法更改它。当我尝试用这种方法初始化UIImage时,结果是nil

使用这种图像为例: The path to the file

The full tree

要创建一个UIImage我使用这个:

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] 

一切看起来罚款在调试,直到我真正创建图像,它返回为空。

调试器中图像的完整路径为/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

我错过了什么?

回答

0

“图像”只是一个组而不是一个文件夹,所以.../ReadMeAStory.app/ReadMeAStory/images/不存在。 你在做什么[AppearanceUtils skinBasePath]

也许这将帮助: NSString *path=[[NSBundle mainBundle] pathForResource:@"button_181_43" ofType:@"png" inDirectory:@"skin/wood"];