I have a UITapGestureRecognizer on a label as:
cell.label.userInteractionEnabled = true
let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.labelTapped))
cell.label.addGestureRecognizer(gestureRecognizer)
I’d want it to change text when a user taps on it. After hours of looking for an answer on Stackoverflow, I’ve reached at a point where I could change text of a label. But it also changes text on other cell labels. Here’s what I implemented:
func labelTapped(recognizer: UIGestureRecognizer){
print("Label tapped.")
let position: CGPoint = recognizer.locationInView(self.tableView)
let indexPath: NSIndexPath = self.tableView.indexPathForRowAtPoint(position)!
let cell = self.tableView.cellForRowAtIndexPath(indexPath) as! DataTableViewCell
cell.label.text = "Test."
}
Help me find a solution.