2013-11-26 54 views
2

這是我的代碼,每當我點擊鏈接didSelectLinkWithURL委託不獲取調用。任何幫助表示讚賞。TTTAttributedLabel代表didSelectLinkWithURL是沒有得到所謂的iPhone

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

} 

回答

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