How to determine which image was used quickly

I created 6 UIImageViews in the ViewController and later I will add TapGestureRecognizers to all of them.

I want to make it so that depending on which image was clicked, another ViewController will open and display certain information.

For this to happen, I need to know which image was clicked. How can I do this in Swift?

+3


source to share


1 answer


The UIGestureRecognizer has a "view" property, which is the property you add to. For this example, imageView.



func tap(gesture: UIGestureRecognizer) {
    println(gesture.view!.tag) // You can check for their tag and do different things based on tag
}

let img = UIImageView()
img.userInteraction = true
img.tag = 0
img.addGestureRecognizer(UITapGestureRecognizer(self, action: "tap:"))

      

+3


source







All Articles