0
有沒有辦法檢測哪個鏈接被按下?我可以打開「下一個」VC,但我似乎無法檢測到哪個單詞。這是我如何檢測哪些單詞應該是鏈接:TTTAttributedLabel檢測多個鏈接
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];
}
}
隨着你的幫助和一些調整它的作品。謝謝! – hugocarlmartin