我在一个ViewController上创建了6个UIImageView,并且稍后将为它们添加TapGestureRecognizers。
我希望根据所点击的图像,打开另一个ViewController并显示特定的信息。
为了实现这一点,我需要知道哪个图像被点击了。在Swift中,我该如何做到这一点?
我在一个ViewController上创建了6个UIImageView,并且稍后将为它们添加TapGestureRecognizers。
我希望根据所点击的图像,打开另一个ViewController并显示特定的信息。
为了实现这一点,我需要知道哪个图像被点击了。在Swift中,我该如何做到这一点?
UIGestureRecognizer有一个属性'view',它是你要添加的视图。在这个例子中是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:"))
img.tag = 0
,我如何获取所选图像的所选单元格? - jo3birdtalk