UIImageView 不会加载图像
我正在尝试探索 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];
}
当我运行它时,我总是得到空白屏幕?为什么?谢谢。
I'm trying to explore UIImageView so I added an image "Logo.jpg" to my projet (I'm new to iPad programming) which is LoadImageProject but iI can't get this image load to my view?
In my Interface builder (LoadImageViweController.xib) I drag a UIImageView and added it then connect it to the File's owner
My code :
LoadImageViweController.h
{
IBOutlet UIImageView *image;
}
@property (nonatomic, retain) IBOutlet UIImageView *image;
@end
and in the implementation file LoadImageViweController.m i added this to the viewDidLoad method :
- (void)viewDidLoad
{
[super viewDidLoad];
//declare the Image
UIImage *logo = [UIImage imageNamed:@"Logo.jpg"];
// init the UIImageView with the logo image
[self.image initWithImage:logo];
}
When iI run it iI got always get blank screen? Why? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需在您的 viewDidLoad 方法中使用它..
这肯定会对您有所帮助....
Just use this in your viewDidLoad method..
This will help you definitely....
您是否将该文件正确添加到您的项目中?有时我发现正确添加它很棘手。添加新资源(例如您案例中的图像)时,您必须清理并运行项目,以便脚本识别您的资源。
Did you add the file correctly to your project? Sometimes I find it tricky to add it properly. You have to clean and run your project when adding new resources (such as images in your case) for the script to recognize your resources.