2014/04/03

Solve "Could not load the image referenced from a nib in the bundle with identifier"

storyboard 是在 IOS 5 中加入的新控件,能夠更加清晰、簡單的整合多個 ViewController 的關係。storyboard 也是 xml 格式,就像 Android xml 檔案一樣,可用拖拉的方式建立畫面。比較不一樣的是storyboard 的 xml 不是給工程師看的,因為它不像 android 的 xml 清晰易懂,storyboard xml 混雜許多其他資訊,而且是 " 唯讀 " 所以平常比較不會去查看。
在開發 IOS app 時,有使用 storyboard 的朋友應該知道,若在 storyboard 中設置某些參數,卻沒有對應的 references,程式可能無法執行,例如 Button click event 後要直行的方法,若程式中沒有定義相對的方法程式根本不能執行。但如果只是圖片呢?它不但能夠執行,還不會 crash,但在 console 中卻可以看到如下的錯誤訊息

2014-03-28 10:14:13.352 kokola[198:707] Could not load the "btn_topbar1_pressed.png" image referenced from a nib in the bundle with identifier "com.maxkit.kokola"
2014-03-28 10:14:13.355 kokola[198:707] Could not load the "btn_topbar5_pressed.png" image referenced from a nib in the bundle with identifier "com.maxkit.kokola"
2014-03-28 10:14:44.205 kokola[198:707] Could not load the "btn_topbar6_pressed.png" image referenced from a nib in the bundle with identifier "com.maxkit.kokola"

原因

  1. 你沒有將圖片加入 xcode
  2. 您刪除了圖片,但是 storyboard 中的定義上未清除

solve

  1. 若是上述第一種情況,只要將圖片重新加入 xcode 專案中就可以了
  2. 若是第二種情況,那您要去 storyboard 中將定義清除
       (1) 開啟 storyboard 點擊工具列右上 " show the version editor "

       (2) 開啟後會看到 storyboard xml 檔

       (3) 搜尋一下圖片名稱,搜到後往上找一下看看是哪個元件的圖片
              ※ 上圖可看到是 UIButton 元件在 select 狀態下時使用的圖片
       (4) 再往上看一點,可看到綠色註解,是 xcode 產生的註解,可看出元件再哪個 ViewController
             ※ xml code 是唯讀,在這裡刪掉是沒有意義的!
       (5) 回到 " show the standard editor " ( 檢視 UI )
       (6) 用剛剛的線索找到元件,並刪除圖片



References

沒有留言:

張貼留言