UIImageView - 如何获取分配的图像的文件名? [英] UIImageView - How to get the file name of the image assigned?

查看:47
本文介绍了UIImageView - 如何获取分配的图像的文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以读取UIImageView的 UIImage的名称目前存储在 UIImageView?

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];

推荐答案

不.你不能那样做.

原因是 UIImageView 实例不存储图像文件.它存储一个显示 UIImage 实例.当您从文件制作图像时,您会执行以下操作:

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"];

一旦完成,就不再有对文件名的任何引用.UIImage 实例包含数据,不管它是从哪里得到的.因此,UIImageView 不可能知道文件名.

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.

此外,即使可以,您也永远无法从视图中获取文件名信息.这打破了 MVC.

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

这篇关于UIImageView - 如何获取分配的图像的文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆