swift,如何从UIImageView获取当前显示的图像文件名 [英] swift, How to get currently displayed image file name from UIImageView

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

问题描述

我想获取当前显示在UIImageView上的图像文件名.我试图按如下方式获取它:

I want to get the image file name which is currently displayed at UIImageView. I tried to get it as follow:

let currentImage = alien.image // !alien is my image view 
println(currentImage?.description)

但它会打印:

Optional("<UIImage: 0x7fa61944c3d0>")

推荐答案

您不能这样做.既不迅速也不客观-c.

You can't do this. Neither in swift nor objective-c.

要做的是存储要检索的数据.也就是说...将名称存储在某个地方,然后使用它来加载图像.并非如此.

The thing to do is to store the data you want to retrieve. That is... store the name somewhere and use that to load the image. Not the other way around.

因此,请创建类似于imageName的属性,然后使用该属性加载图像.

So create a property something like imageName and then use that to load the image.

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

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