Variable UIImageView
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 va开发者_StackOverflowlue 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?
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"]];
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"]];
精彩评论