UIImageView不会加载图像

时间:2011-04-08 10:10:46

标签: ipad uiimageview uiimage

我正在尝试探索UIImageView所以我在我的项目中添加了一个图像“Logo.jpg”(我是iPad编程的新手),这是LoadImageProject,但是我无法将此图像加载到我的视图中?

在我的界面构建器( LoadImageViweController.xib )中,我拖动UIImageView并添加它,然后将其连接到文件的所有者

我的代码:

  

LoadImageViweController.h

{
    IBOutlet UIImageView *image;
}

@property (nonatomic, retain) IBOutlet UIImageView *image;

@end

并在实现文件 LoadImageViweController.m 中我将其添加到 viewDidLoad 方法:

- (void)viewDidLoad
{
    [super viewDidLoad];
    //declare the Image
    UIImage *logo = [UIImage imageNamed:@"Logo.jpg"];
    // init the UIImageView with the logo image
    [self.image initWithImage:logo];

}

当我运行它时,我总是得到空白屏幕?为什么?感谢。

2 个答案:

答案 0 :(得分:2)

只需在viewDidLoad方法中使用它..

 image.image = logo;

这肯定会帮助你......

答案 1 :(得分:0)

您是否正确地将文件添加到项目中?有时我发现正确添加它很棘手。在添加新资源(例如您的图像中的图像)时,您必须清理并运行项目,以便脚本识别您的资源。