TTTAttributedLabel Delegate didSelectLinkWithURL не вызывается в iPhone

Это мой код, когда я нажимаю на ссылку didSelectLinkWithURL делегат не вызывается. Любая помощь приветствуется.

    TTTAttributedLabel *tttLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];
    NSString *labelText = @"Lost? Learn more.";
    tttLabel.text = labelText;
    NSRange r = [labelText rangeOfString:@"Learn more"];
    [tttLabel addLinkToURL:[NSURL URLWithString:@"action://show-help"] withRange:r];
    [self.view addSubview:tttLabel];
    tttLabel.userInteractionEnabled=YES;


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

        UIWebView *web=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
         NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
        [web loadRequest:requestObj];
        [self.view addSubview:web];

}

1 ответ

Решение

Убедитесь, что ваш класс реализует TTTAttributedLabelProtocol, и установите tttLabel.delegate = self; В заголовочном файле:

@interface yourClass : parentClass <TTTAttributedLabelDelegate> {
}

В файле реализации

TTTAttributedLabel *tttLabel = [[TTTAttributedLabel alloc]initWithFrame:CGRectMake(10, 10, 200, 200)];
tttLabel.delegate = self;
NSString *labelText = @"Lost? Learn more.";
tttLabel.text = labelText;
NSRange r = [labelText rangeOfString:@"Learn more"];
[tttLabel addLinkToURL:[NSURL URLWithString:@"action://show-help"] withRange:r];
[self.view addSubview:tttLabel];
tttLabel.userInteractionEnabled=YES;

- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url {
      NSLog(@"Did click");
}
Другие вопросы по тегам