2

这是我的代码,每当我单击链接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];

}
4

1 回答 1

5

确保你的类实现了 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");
}
于 2013-11-26T11:38:44.080 回答