通過NSBundle獲取文件路徑的細節問題

NSString *imagePath = [NSString stringWithFormat:@"%@/changshuImages/1.jpg",[[NSBundle mainBundle] bundlePath]];

通過NSBundle來獲取項目中的文件路徑,然後創建UIImage對象,但是問題是創建出來的UIImage對象始終爲null。

後來發現在往項目中拖拽文件的時候,如果想通過bundlePath來獲取路徑,那麼在選擇的時候有區別。

一般情況下我們是這樣拖拽

Destination:copy items into destination group's folder (if needed)

//導入文件的時候會是邏輯結構,而不是物理結構,目錄結構圖標如下,黃色的文件夾結構,和構建的Group是一樣的

Folders: create groups for any added folders

Add to targets :projectName;

這樣的選擇我們永遠都無法通過bundlePath來獲取文件的路徑





Destination:Copy items into destination group's folder (if needed)

//創建引入的是藍色的文件夾結構,物理路徑

Folders:create folder references for any added folders

Add to targets: projectName

這樣就可以通過bundlePath來獲取路徑了


YES !!! :-)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章