views:

33

answers:

2

I have a working UIImageView, but I want to change it based on a certain variable so I have this: a string called imagevariable(which holds the value of image1 which is a png resource in my project). So I have this:

imageView.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:@"imagevariable" ofType:@"png"]];

But it doesn't work. Can someone help?

+1  A: 

You are passing image variable as a string which means, that you will literally search for an image named "imagevariable.png". Instead take away that @"" and make it like this:

imageView.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:imagevariable ofType:@"png"]];
thyrgle
Thank you so much!
Rushil
+1  A: 

By wrapping the variable name imagevariable in quotes it is being treated as a string literal, try this instead

imageView.image = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:imagevariable ofType:@"png"]];
acqu13sce
Thank you so much!
Rushil