2012-04-12 102 views
0

我讀了一些項目,很高興找到如何add real subfolders 但是none的任何解決方案讓我看到我的文件在子文件夾中。全部返回零。使用子文件夾不適用於pathForResource也不適用URLforResource

Path problems with XCode

inDirectory

我試過pathForResource和URLforResource和inDirectory methodes。

 //NSString *W = [[NSBundle mainBundle] pathForResource:@"LS_ADINFO_0000_LFSB" ofType:@"xml" inDirectory:@"/2012-03-08%20(Published%20as%2008%20MAR%202012)/AERODROMES/LFSB/"]; 
     //urlPDF = [NSURL URLWithString:W]; 
     // DEBUG output: urlPDF = nil 

     //urlPDF = [[NSBundle mainBundle] URLForResource:@"LFSB/LS_ADINFO_0000_LFSB.xml" withExtension:nil]; 
     // DEBUG output: urlPDF = nil 


     //urlPDF = [[NSBundle mainBundle] URLForResource:@"LS_ADINFO_0000_LFSB.xml" withExtension:nil]; 
     // DEBUG output: urlPDF = file://localhost/Users/siri/Library/Application%20Support/iPhone%20Simulator/5.0/Applications/1F5953CD-1E13-40D4-9497-8313F9DDEA77/SwissVfrm03.app/LS_ADINFO_0000_LFSB.xml 

如何在XCode中設置子目錄以訪問iPad應用程序?

回答

5

在iOS應用程序中,非本地化資源位於軟件包目錄的頂層。您可以按路徑創建自定義捆綁包,但默認情況下,無論您在Xcode中設置了哪些目錄,所有資源都位於捆綁包的頂層。

iOS Bundle Programming Guide

0

我有-pathForResource:ofType:inDirectory:一個奇怪的問題。儘管我的資源文件的目錄結構被忠實地保存在最終版本中(我通過在Finder中構建應用程序並在Finder中檢查應用程序包的內容來檢查這個目錄結構),但它會返回一個非零(但是錯誤的)如果目標文件駐留在應用程序包的根目錄下,那麼該路徑就是如此。

例如,

該文件位於:

.../MyApp.app/Subdir1/Subdir2/file.png

但下面的代碼:

[[NSBundle mainBundle] pathForResource:@"file" ofType:@"png" inDirectory:@"Subdir1/Subdir2"] 

...給代替:

.../MyApp.app/file.png

將所有目錄名更改爲ASCII字符修復了問題。

相關問題