0

Possible Duplicate:
UIImageView - How to get the file name of the image assigned?

I can't figure out how to find what image file an image view is displaying or if it is being displayed at all. For example lets say I have an image view. By the tag of the image view I want to be able to determine what file (the name of the file) is being displayed through the image view?

I can't seem to find an answer to what I thing is a very simple question...

I know I can change the image of an imageview like this...

[(UIImageView*)[self.view viewWithTag:ImageViewTag] setImage:[UIImage imageNamed:imageTitle]];

But how can I see what image an image view is already displaying?

Community
  • 1
  • 1
The Man
  • 1,462
  • 3
  • 23
  • 45

1 Answers1

3

As the link in Ben's comment explains, there is no native way to do this. However, you could easily create this behavior yourself.

You can subclass UIImageView and add a new instance variable:

NSString* imageFileName;

Then you could override setImage, first setting imageFileName to the filename of the image you're setting, and then calling [super setImage:imageFileName]. Something like this:

-(void) setImage:(NSString*)fileName
{
   imageFileName = fileName;
   [super setImage:fileName];
}

Just because it can't be done natively doesn't mean it isn't possible :)

WendiKidd
  • 4,333
  • 4
  • 33
  • 50
  • Ideally if a duplicate has been identified, you would post any new answers on the original question. The duplicate will be linked back to that one. That keeps information in one place, and makes questions more valuable and easier to use for future searchers. – jscs May 22 '12 at 01:23
  • @JacquesCousteau Oh, I see. Thank you for the information--I will go do that now! – WendiKidd May 22 '12 at 01:23