Quantcast
Channel: Coding and Programing » cocoa
Viewing all articles
Browse latest Browse all 10

UIImageView – How to get file name of image assigned

$
0
0

Problem And Question

Is it possible to read the name of an UIImageView's UIImage
that’s presently stored in the UIImageView?

I was hoping you could do something kind of like this, but haven’t figured it out.

NSString *currentImageName = [MyIImageView getFileName];

Best Solution And Answer

Nope. You can’t do that.

The reason is that a UIImageView instance does not store an image file. It stores a displays a UIImage instance. When you make an image from a file, you do something like this:

UIImage *picture = [UIImage imageNamed:@"myFile.png"];

Once this is done, there is no longer any reference to the filename. The UIImage instance contains the data, regardless of where it got it. Thus, the UIImageView couldn’t possibly know the filename.

Also, even if you could, you would never get filename info from a view. That breaks MVC.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles



Latest Images