Reputation: 453
I've been stuck with adding a UIImage to my iPhone application, to add an image i usually used the name of the image and put it like that :
UIImage* myImage1 = [UIImage imageNamed:@"myImage.png"];
But in my application i don't know the name of the image when i'm writting the code, i've got the image name with a webservice and i put it in a NSString.
So i have a string m_image1
, and i want to display the image in a UIImage like that :
UIImage* myImage1 = [UIImage imageNamed:m_image1];
But nothing appears on the screen, when i use NSLog
to show if m_image1
has the right string it works, and when i paste what is print in the log in the imageNamed it works.
I've already tried using the path of my application, but nothing do it ! So i don't know what to try anymore !
That's my all block of code :
NSLog(@"m_image1 : %@",m_image1);
UIImage* myImage1 = [UIImage imageNamed:m_image1];
m_result1ImageView = [[UIImageView alloc] initWithImage:myImage1];
m_result1ImageView.frame = CGRectMake(0.f, 0.f, 163.f, 260.f);
[m_ScrollImages addSubview:m_result1ImageView];
Everything work just fine, when i put :
UIImage* myImage1 = [UIImage imageNamed:@"myImage.png"];
instead of :
UIImage* myImage1 = [UIImage imageNamed:m_image1];
it display the image !
Upvotes: 3
Views: 5258
Reputation: 1409
I think you have not copied exactly the images in your application bundle that is being not displayed .
Try & check removing bunch of images and add those again in your project.
Upvotes: 0
Reputation: 3437
I think your image is not in the resources!
Check your image: Go to the Project Navigator
and click on blue icon which is your project. Now in Targets
click on your target and go to Build phases
tab and check Copy bundle resources
.
Your image file must be in the list, if it is not add it and check the program again!
I hope it be useful for you!
Upvotes: 4
Reputation: 8460
try this code ,
m_result1ImageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: m_image1]]];
Upvotes: 1