Yashu
Yashu

Reputation: 535

UIImage is empty after calling imageWithContentsOfFile

enter image description here As you can see, that I have put my the national flags in a folder in Xcode and I am trying to display it to the navigation bar. However, it is not showing up and I found out:

NSString *imageName = [NSString stringWithFormat:@"%@.icns",countryName]; UIImage *image = [UIImage imageWithContentsOfFile:imageName];

image is "nil".

Any idea? Thanks!

Upvotes: 0

Views: 3215

Answers (3)

Sumanth
Sumanth

Reputation: 4921

Where was the image path you are sending NSString to here

 UIImage imageWithContentsOfFile:imageName

send the path to that method. or make like this

 UIImage *image = [UIImage imageNamed:[NSString stringwithFormat:@"%@.icns",countryName]];

Upvotes: 1

user1471790
user1471790

Reputation:

You could use like this

 NSString *imageName = [NSString stringWithFormat:@"%@.icns",countryName];
 UIImage *image =  [UIImage imageNamed:imageName];

Please Try This

Upvotes: 1

fzwo
fzwo

Reputation: 9902

Check whether the file actually exists. I suspect it doesn't. Use [NSFileManager defaultManager] fileExistsAtPath:.

Upvotes: 1

Related Questions