2011-06-11 63 views
0

我在捆綁包myBundle中創建了一個目錄MyDirectory。然後我在MyDirectory中放置一個圖像myImage.png。但致電NSBundle - 在捆綁中查找資源?

[myBundle pathForResource: @"myImage" ofType: @"png"] 

未找到圖像。我錯過了什麼?

編輯:澄清,如果圖像是在捆綁的頂層,它發現它就好。

回答

3

首先,您必須將圖像添加到包中。如果你已經這樣做了,我猜你會在將圖像添加到項目中時添加文件夾引用。如果是這樣,您應該使用圖像名稱指定文件夾層次結構。

[myBundle pathForResource:@"MyDirectory/myImage" ofType:@"png"]; 

編輯:迪帕克下面評論,甚至還有一個更好的方法pathForResource:ofType:inDirectory:

[myBundle pathForResource:@"myImage" ofType:@"png" inDirectory:@"MyDirectory"]; 
+2

+1使用更好的方法是'pathForResource:ofType:inDirectory:'。 – 2011-06-11 15:35:44

0

您是否將圖像添加到您的Xcode項目(project.pbxproj)?

+0

沒有,但我加管束。 – 2011-06-11 14:58:09

相關問題