Contact Us

Use the form on the right to contact us.

You can edit the text in this area, and change where the contact form on the right submits to, by entering edit mode using the modes on the bottom right. 


Oak Ridge, TN, 37830
United States

Swift-Snips

How to get currently displayed image name from UIImageView

Wade Cantley

I want to get the image name which is currently displayed at UIImageView but can't find a means to get the image name.

As a work around, for images that I need to reference at a later time, I use the restoration ID to store the image name.

I used restoration ID in this way so that I could connect multiple buttons to the same @IBAction and identify them based on the image name stored in the restoration ID and run logic about what I want to display or hide.

There might be better ways but this worked in a pinch.

I put the image name in as the restoration ID.

Here is where I designate the file for the image..

And I just copy that and put it in as the restoration ID.

(note: that is not what this was intended to be used for as it is really meant for customizing state reference but if that is not relevant to the purpose of your view, then it should work fine.)

Referenced in code when the button is selected.


//Connected to several onboarding buttons.
@IBAction func onBoardingButton(sender: UIButton) {

    println(sender.restorationIdentifier)
}

ID printed out.

You can also tag your images and keep the reference to those images via the tag.

nd the reference is just as easy.


@IBAction func onBoardingButton(sender: UIButton) {

    println(sender.restorationIdentifier!)
    println(sender.tag)
}

hile it doesn't seem like we can discern what file was used to fill the imageview (that I know of and based on a little looking around myself) attaching hard references to a view (image, button, etc..) allows me to make the connection code side and figure out which image (or in my case button) is being used.