Bisoux
Bisoux

Reputation: 522

Image not loaded in UIImageView

I have a UIViewcontoroller subclass and the following code is in my viewdidload ,

CGRect cellFrame = CGRectMake(0, 0, 320, 44);
UIImageView *myImageView = [[UIImageView alloc] initWithFrame:cellFrame ]  ;
[myImageView setImage:[UIImage imageNamed:@"first.png"]];
self.view=myImageView;
[super viewDidLoad];

The image file is in the same directory as the class files. The issue is when the app is loaded the image is not shown just a blank screen.

Thanks

Upvotes: 0

Views: 145

Answers (2)

viewDidAppear
viewDidAppear

Reputation: 76

please check if [UIImage imageNamed:@"first.png"] is returning a nil?

Upvotes: 0

Inder Kumar Rathore
Inder Kumar Rathore

Reputation: 40008


1.Instead of self.view=myImageView; use [self.view addSubview:myImageView];

1.Also[super viewDidLoad]; call this first before any statement.
3.Then check if the [UIImage imageNamed:@"first.png"] is returning image.
4.Also check first.png is the name of the file.Note names are case sensitive for devices.

Upvotes: 2

Related Questions