ios - TTTAttributedLabel 检测多链接

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

    }
}

最佳答案

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

关于ios - TTTAttributedLabel 检测多链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20179835/

相关文章:

ios - 我怎么知道我的应用程序在后台运行?

iphone - 值 1e100f 代表什么?

iphone - NSURLConnection 用于异步 Web 服务调用的 NSURLRequest 代理

objective-c - cocoa , objective-c NIB 加载两次

objective-c - 使用 OS X 沙箱写入多个文件

ios - 协议(protocol)和委托(delegate)到底是什么,它们在 IOS 中是如何使用的?

iphone - 从 UIGraphicsGetImageFromCurrentImageContext 泄漏返回的 UIImage

ios - swift 2.0 : Reading HealthKit HeartRate Data - unexpectedly found nil while unwrapping an Optional

iphone - UIActionSheet 按钮未加载新 View

iphone - 是否有 iPhone OS4 iCal API