2

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

}
Forge
  • 6,538
  • 6
  • 44
  • 64
Gopinath Shiva
  • 3,822
  • 5
  • 25
  • 48

1 Answers1

5

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");
}
Durican Radu
  • 1,327
  • 11
  • 12