ak2g
ak2g

Reputation: 1673

UITapGestureRecognizer with tap event

I am trying to fire event with UITapGestureRecognizer on different uiview but it is not working.

var tap = UITapGestureRecognizer(target: self, action: Selector("tappedMe"))
        AUIView.addGestureRecognizer(tap)
        AUIView.tag = 1

BUIView.addGestureRecognizer(tap)
        BUIView.tag = 2


   func tappedMe()
    {

        if AUIView.tag == 1
        {
            println("1")
        }
         else if BUIView.tag == 2
        {
            println("2")
        }
}

Upvotes: 0

Views: 406

Answers (1)

ZeMoon
ZeMoon

Reputation: 20274

You cannot add the same gesture recognizer to multiple views. This answer explains why.

Either declare a new gesture recognizer, or create a copy of the existing one before adding it to the other view.

BUIView.addGestureRecognizer(tap.copy())

Upvotes: 1

Related Questions