0

有没有办法检测哪个链接被按下?我可以打开“下一个”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];

    }
}
4

1 回答 1

2

您应该在 URL 中包含该词。因此,action://at您可以使用; 而不是使用action://at?foo; 在您的回调中,您可以获得queryURL 的一部分,这将是点击的单词。

于 2013-11-24T20:20:30.630 回答