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