2012-07-21 159 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

如果只发生在您的应用在设备上运行但与模拟器一致的情况下,请检查映像名称,因为它在设备中区分大小写。