2013-11-24 53 views
0

有沒有辦法檢測哪個鏈接被按下?我可以打開「下一個」VC,但我似乎無法檢測到哪個單詞。這是我如何檢測哪些單詞應該是鏈接:TTTAttributedLabel檢測多個鏈接

NSArray * words = [cell.lblDescription.text componentsSeparatedByString:@「」];

for (NSString *word in words) { 
     if ([word hasPrefix:@"@"]) { 
      at = [cell.lblDescription.text rangeOfString:word]; 
      [cell.lblDescription addLinkToURL:[NSURL URLWithString:@"action://at"] withRange:at]; 

     }else if ([word hasPrefix:@"#"]) { 
      hash = [cell.lblDescription.text rangeOfString:word]; 
      [cell.lblDescription addLinkToURL:[NSURL URLWithString:@"action://hash"] withRange:hash]; 
     } 
    } 

這裏是鏈接鏈接的方法:

- (void)attributedLabel:(TTTAttributedLabel *)label didSelectLinkWithURL:(NSURL *)url { 

if ([[url scheme] hasPrefix:@"action"]) { 
    if ([[url host] hasPrefix:@"hash"]) { 
     /* load help screen */ 
     UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"viewTags" bundle:nil]; 
     OIOI_VC_ViewTags *viewController =[storyboard instantiateViewControllerWithIdentifier:@"viewTags"]; 
     viewController.str_word = ??????; 
     [self.navigationController pushViewController:viewController animated:YES]; 

    } 
} 

回答

2

你應該在URL中包含的單詞。因此,您可以使用action://at?foo;而不是使用網址action://at;在你的回調中,你可以得到query網址的一部分,這將是被點擊的單詞。

+0

隨着你的幫助和一些調整它的作品。謝謝! – hugocarlmartin