【问题标题】:TTTAttributedLabel detect multi linksTTTAttributedLabel 检测多链接
【发布时间】:2013-11-24 19:26:43
【问题描述】:

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

    }
}

【问题讨论】:

    标签: ios iphone objective-c uilabel tttattritubedlabel


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多