2012-08-27 77 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"];