Ali
Ali

Reputation: 4245

Image won't load in UIImageView iphone app

I'm trying to display an image in a UIImageView only in the first launch of the app. So after using NSUserDefaults to detect that successfully I try to load an image called firstLaunch.png in the MainViewController.

I created the UIImageView IBOutlet and connected and everything works fine but the image DOESN'T load. Though later somewhere else in my code I can update the UIImageView successfully. Here is my line where I try to load the image to the UIImageView:

[countDownImage setImage:[UIImage imageWithContentsOfFile:@"firstLaunch.png"]];

Upvotes: 1

Views: 3078

Answers (1)

user756245
user756245

Reputation:

You can try getting the path to the file.
So assuming the image is in the app bundle, get the path before with :

NSString *imgPath = [NSBundle mainBundle] pathForRessource:@"firstLaunch"
                                                    ofType:@"png"];
[countDownImage setImage:[UIImage imageWithContentsOfFile:imgPath]];

Another way is :

[countDownImage setImage:[UIImage imageNamed:@"firstLaunch.png"]];

Upvotes: 3

Related Questions