TTTAttributedLabel检测多个链接

时间:2013-11-24 19:26:43

标签: ios iphone objective-c uilabel tttattritubedlabel

有没有办法检测哪个链接被按下了?我可以打开"下一个" VC,但我似乎无法检测到哪个词。这就是我如何检测哪些词应该是链接:

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

    }
}

1 个答案:

答案 0 :(得分:2)

您应该在网址中包含该字词。因此,您可以使用action://at,而不是使用action://at?foo的网址。在你的回调中,你可以获得网址的query部分,这将是被点击的字词。