1

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"]]; 

1 Answer 1

3

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"]]; 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot. I actually tried the 1st method you suggested already but it didn't work. Maybe because I read the image to an NSData. Anyways the 2nd method worked great.[countDownImage setImage:[UIImage imageNamed:@"firstLaunch.png"]];

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.