I am using a NIB file to layout a custom table view cell. This cell has a label with outlet called lblName. Adding a UITapGestureRecognizer to this label never fires the assoc
You can use below code to add tap gesture on UILable in UITableView cell
UITapGestureRecognizer *tapGeature = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lblClick:)];
tapGeature.delegate =self;
tapGeature.numberOfTapsRequired = 1;
cell.lbl.userInteractionEnabled = YES;
[cell.lbl addGestureRecognizer:tapGeature];
and to access the selector method
- (void)lblClick:(UITapGestureRecognizer *)tapGesture {
UILabel *label = (UILabel *)tapGesture.view;
NSLog(@"Lable tag is ::%ld",(long)label.tag);
}
For Swift
let tapGesture : UITapGestureRecognizer = UITapGestureRecognizer.init(target: self, action: #selector(lblClick(tapGesture:)))
tapGesture.delegate = self
tapGesture.numberOfTapsRequired = 1
cell.lbl.userInteractionEnabled = true
cell.lbl.tag = indexPath.row
cell.lbl.addGestureRecognizer(tapGesture)
func lblClick(tapGesture:UITapGestureRecognizer){
print("Lable tag is:\(tapGesture.view!.tag)")
}