TTTAttributedLabel代表didSelectLinkWithURL没有被调用

我在设置自定义单元格中TTTAttributedLabel遇到问题。 我已经检查了很多post,仍然没有想到如何解决这个问题。 (我可以看到在这个自定义标签的url样式,但如果我点击它没有发生)。

CustomCell.h:

 @interface MyCustomCell : UITableViewCell<TTTAttributedLabelDelegate> @property (nonatomic, strong, readonly) UITapGestureRecognizer *tapRecognizer; @property (nonatomic, strong, readonly) UILabel *senderLabel; @property (nonatomic, strong, readonly) UILabel *timeLabel; @property (nonatomic, strong, readonly) UILabel *dateLabel; @property (nonatomic, strong) TTTAttributedLabel *customTextLabel; @end 

CustomCell.m:

 @implementation MyCustomCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { _dateLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _dateLabel.textAlignment = NSTextAlignmentCenter; _dateLabel.font = [UIFont boldSystemFontOfSize:12.0]; _dateLabel.textColor = [UIColor grayColor]; _dateLabel.text = @"2015-10-10"; _dateLabel.userInteractionEnabled = false; _senderLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _senderLabel.textAlignment = NSTextAlignmentLeft; _senderLabel.font = [UIFont boldSystemFontOfSize:14.0]; _senderLabel.textColor = [UIColor whiteColor]; _senderLabel.userInteractionEnabled = false; _timeLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _timeLabel.userInteractionEnabled = false; _timeLabel.textAlignment = NSTextAlignmentCenter; _timeLabel.font = [UIFont boldSystemFontOfSize:11.0]; _timeLabel.textColor = [UIColor whiteColor]; _customTextLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero]; _customTextLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink; _customTextLabel.delegate = self; _customTextLabel.backgroundColor = [UIColor clearColor]; _customTextLabel.numberOfLines = 0; _customTextLabel.lineBreakMode = NSLineBreakByWordWrapping; _customTextLabel.textColor = [UIColor blackColor]; _customTextLabel.font = [UIFont systemFontOfSize:18.0]; [self.textLabel addSubview:_customTextLabel]; _customTextLabel.userInteractionEnabled = true; self.imageView.userInteractionEnabled = YES; self.imageView.layer.cornerRadius = 5.0; self.imageView.layer.masksToBounds = YES; } return self; } 

谢谢你的帮助。

  NSString *text = @"Hello this is https://www.google.com"; _customTextLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(0, 100, 300, 20)]; _customTextLabel.enabledTextCheckingTypes = NSTextCheckingTypeLink; _customTextLabel.delegate = self; _customTextLabel.backgroundColor = [UIColor clearColor]; _customTextLabel.numberOfLines = 0; _customTextLabel.lineBreakMode = NSLineBreakByWordWrapping; _customTextLabel.textColor = [UIColor blackColor]; _customTextLabel.font = [UIFont systemFontOfSize:18.0]; _customTextLabel.text = text; [self.view addSubview:_customTextLabel]; 

并设置TTTAttributedLabel委托方法工作正常请检查:

 - (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url { }