suresh
suresh

Reputation: 53

Pass UITextView tag as a parameters in UITapGestureRecognizer in swift 5

Is there any way to pass UITextView Tag in UITapGestureRecognizer #Selector method in swift 5?

like below code

if yes -> How?
if no -> Why?

let txtView1Tap = UITapGestureRecognizer(target: self, action: #selector(textViewTapped(_:),tag: txtView1.tag))
let txtView2Tap = UITapGestureRecognizer(target: self, action: #selector(textViewTapped(_:), tag: txtView2.tag))

txtView1.addGestureRecognizer(txtView1Tap)
txtView2.addGestureRecognizer(txtView1Tap)

Upvotes: 0

Views: 61

Answers (1)

vadian
vadian

Reputation: 285082

No, because there is no API to do that.

But you can get the text view from the UITapGestureRecognizer with the view property

@obj func textViewTapped(_ sender : UITapGestureRecognizer) {
    let textView = sender.view as! UITextView
    if textView.tag == ...
}

Upvotes: 1

Related Questions