2012-07-21 90 views
1

我有一個使用一堆PNG文件的工作應用程序;它運行沒有問題。我只是從iconfinder.com下載了兩個圖標,並且無法將它們加載到我的應用程序中。iphone uiimage not loading

這裏是我的代碼:

showKeyboardImage = [UIImage imageNamed:@"Bonjour.png"]; 
printf("Bonjour %p %g %g\n", showKeyboardImage, showKeyboardImage.size.width, showKeyboardImage.size.height); 

// http://www.iconfinder.com/icondetails/36137/32/add_keyboard_icon 
showKeyboardImage = [UIImage imageNamed:@"1342878368_keyboard_add.png"]; 
printf("showKeyboardImage %p %g %g\n", showKeyboardImage, showKeyboardImage.size.width, showKeyboardImage.size.height); 

// http://www.iconfinder.com/icondetails/36138/32/delete_keyboard_icon 
hideKeyboardImage = [UIImage imageNamed:@"1342878356_keyboard_delete.png"]; 
printf("hideKeyboardImage %p %g %g\n", hideKeyboardImage, hideKeyboardImage.size.width, hideKeyboardImage.size.height); 

下面是輸出:

Bonjour 0xbd33f70 32 32 
showKeyboardImage 0x0 0 0 
hideKeyboardImage 0x0 0 0 

是,所有這三個文件在同一目錄下。是因爲我從互聯網上下載了圖標嗎?我需要標記他們安全使用或什麼?

+0

在你的模擬器或iPhone上發生問題嗎? – 2012-07-21 18:53:04

回答

3

我最近有類似的麻煩。你需要確保你已經將它們添加到你的項目中。在XCode的左側文件中找到您想要圖像位於的文件夾,然後右鍵單擊該文件夾並選擇「將文件添加到'YOUR_PROJECT_HERE'」然後選擇文件並單擊「添加」。希望有所幫助!

+0

就是這樣。現在我感到尷尬。 :) – samwyse 2012-07-21 19:17:00

0

確保您已將文件添加到您的項目中,並檢查它們是否是目標的一部分。在Xcode中,單擊圖像文件,查看文件檢查器(Cmd + Alt + 1),看看是否有「目標成員」複選標記。

還請確保您的代碼中使用了正確的文件名稱。

+0

偉大的建議;我希望我能給你「正確」的國旗。 – samwyse 2012-07-21 19:22:33

+0

您可以至少投票回答:) – calimarkus 2012-07-22 17:40:04

+1

投票要求15聲望:( 一旦我明白了,但我會回來的。 – samwyse 2012-07-29 10:11:48

1

如果只發生在您的應用在設備上運行但與模擬器一致的情況下,請檢查映像名稱,因爲它在設備中區分大小寫。