为什么图像不在UIImageView中显示?

时间:2013-01-03 13:19:24

标签: objective-c ios ios6 uiimageview uiimage

UIImage *image = [UIImage imageNamed:[currentPhoto fileName]];
NSLog(@"%@",[currentPhoto fileName]);
[self.currentImage setImage:image];

它在调试区域中显示正确的图像名称 我想在UIImageView上显示。 currentImage是连接在.h文件中的插座

是不是因为iOS 6的新自动布局功能我没有得到它。 它曾经在iOS 5中工作。

我的目的是在特定场景的UIImageView中显示图像

我还尝试设置我在项目文件夹中复制的默认图像。 但我得到一个错误调试区域如下:

Could not load the "myImage.png" image referenced from a nib in the bundle with identifier "com.xxx.xxx"

3 个答案:

答案 0 :(得分:2)

确保图片名称也带有扩展名(.jpg / .png)。你还为imageView ??

定义了一个iBoutlet

此外,如果问题出在autolayout上,您可以在Xib中禁用它。从这里学习它。 http://www.goodbyehelicopter.com/2012/02/arggh-xcode-4-3-auto-layout-is-on-by-default-how-to-turn-off-auto-layout/

答案 1 :(得分:1)

当您转到文件 - >添加文件“ProjectName”时 弹出窗口。
Xcode选择的默认选项是 “为任何添加的文件夹创建文件夹引用”,如下图所示 正在生产
错误(在调试区域中):
    Could not load the "myImage.png" image referenced from a nib in the bundle with identifier "com.xxx.xxx"

Wrong options selected

解决上述问题:
选择“为任何添加的文件夹创建组”,这次Xcode通常选择的不是这种情况。

enter image description here


解决方案很简单,但有时会发生愚蠢的错误。

答案 2 :(得分:0)

如果您的图片未添加到项目中,则无法进行imageNamed调用。要加载未添加到项目中的图像,请使用此调用

UIImage * image = [UIImage imageWithContentsOfFile:imgFilePath];

相关问题