0

I have a string variable(imageStr) in which I have name of an image I am fetching from sqlite database. How can I assign that string variable as an image name to a imageview?

Code:

UIImageView *imageHolder = [[UIImageView alloc] initWithFrame:CGRectMake(150, 11, 50, 25)];
UIImage *image = [UIImage imageNamed:imageStr];
imageHolder.image=image;
NSLog(@"image in mediView:%@",imageHolder.image);

In the log I am getting NULL value. If I print just "imageStr" then it is giving me string value.

Mark Schultheiss
  • 32,614
  • 12
  • 69
  • 100

1 Answers1

-1

NSLog(@"image in mediView:%@",imageHolder.image);

The above line of code is trying to print a UIImage, which makes no sense because neither UIImageView or UIImage have knowledge of what the name of the image is. What you need to do is subclass UIImageView and add a property that saves this information.

Update: Shan's link above is pretty helpful.

Community
  • 1
  • 1
Lawrence H
  • 467
  • 4
  • 10