Prashanth Narasimha Prashanth Narasimha - 6 months ago 204
iOS Question

Add target to UITextView and UILabel in swift

I have a

UITable
and I have multiple labels and textviews in it. I want a method to be called when touchupinside event is triggered . I used
targetForAction
but i cannot specify
touchUpInside
event in it.And the textview is not editable

On a whole , i want what a button does with
addTarget
to be done by textview and label. Please help me

Answer

add Gesture and try

let tap = UITapGestureRecognizer(target: self, action: #selector(doubleTapped:))
tap.numberOfTapsRequired =1
yourlabel.tag = indexPath.row
yourlabel.addGestureRecognizer(tap)

call method like

func doubleTapped(recognizer: UITapGestureRecognizer) {

        print(recognizer.view.tag)

}

for textview

add yourTextView.delegate = self

func textViewDidChange(textView: UITextView) {
    //do continue your work
}