I have a custom UITableViewCell with some UILabel inside, my goal is to perform different segue if user tap on a UILabel or another one. I could not understand on which sub item of my UITableViewCell user have just tapped on. Is there a way to get on witch item of my UITableViewCell user tapped on and so perform the segue ?? Thank's a lot for any help.
1 ) Enable User interaction for the labels from storyboard ( attribute inspector ) or code using userInteractionEnabled
and set value to true
2 ) In cellForRowAtIndexPath, add a target to these labels using UITapGestureRecognizer
let tap = UITapGestureRecognizer(target: self, action: #selector(didPressOnLabel(_:)))
myLabel.isUserInteractionEnabled = true
myLabel.addGestureRecognizer(tap)
3 ) create a function for this selector
@objc func didPressOnLabel(_ sender:UITapGestureRecognizer) {
print("Label tapped !!")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.