TTTAttributedLabel代表didSelectLinkWithURL没有在iPhone中被调用 [英] TTTAttributedLabel Delegate didSelectLinkWithURL is not getting called in iPhone

查看:126
本文介绍了TTTAttributedLabel代表didSelectLinkWithURL没有在iPhone中被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,每当我单击链接didSelectLinkWithURL代表时都不会被调用.感谢您的帮助.

This is my code, whenever I click the link didSelectLinkWithURL delegate is not getting called. Any help is appreciated.

    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];

}

推荐答案

确保您的类实现了TTTAttributedLabelProtocol,并设置了tttLabel.delegate = self; 在头文件中:

Make sure your class implements TTTAttributedLabelProtocol, and set tttLabel.delegate = self; In the header file:

@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");
}

这篇关于TTTAttributedLabel代表didSelectLinkWithURL没有在iPhone中被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆