Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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]; 
like image 310
Kuberchaun Avatar asked Nov 16 '09 05:11

Kuberchaun


People also ask

What is the difference between UIImage and UIImageView?

UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage .

How do I find my UIImage path?

Once a UIImage is created, the image data is loaded into memory and no longer connected to the file on disk. As such, the file can be deleted or modified without consequence to the UIImage and there is no way of getting the source path from a UIImage.

What is UIImage?

An object that manages image data in your app.


2 Answers

you can use setAccessibilityIdentifier method for any subclass of UIView

UIImageView *image ; [image setAccessibilityIdentifier:@"file name"] ;  NSString *file_name = [image accessibilityIdentifier] ; 
like image 173
Nizar Ahmed Avatar answered Sep 22 '22 00:09

Nizar Ahmed


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.

like image 31
Jonathan Sterling Avatar answered Sep 19 '22 00:09

Jonathan Sterling