How can I add a UITapGestureRecognizer to a UILabel inside a table view cell?

后端 未结 10 1567
萌比男神i
萌比男神i 2021-02-04 00:43

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

10条回答
  •  耶瑟儿~
    2021-02-04 01:35

    You can add next in your cell's -awakeFromNib method

    UITapGestureRecognizer* gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureRecognizerAction:)];
    [self.yourLabel setUserInteractionEnabled:YES];
    [self.yourLabel addGestureRecognizer:gesture];
    

提交回复
热议问题