TTTAttributedLabel Delegate didSelectLinkWithURL is not getting called in iPhone

匿名 (未验证) 提交于 2019-12-03 01:05:01

问题:

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

回答1:

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

@interface yourClass : parentClass <TTTAttributedLabelDelegate> { } 

In the Implementation File

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


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!