2013-11-24 4 views
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]; 

    } 
} 

ответ

2

Вы должны включить слово в URL. Итак, вместо того, чтобы использовать URL-адрес action://at, вы можете использовать action://at?foo; в вашем обратном вызове вы можете получить часть URL-адреса query, и это будет использованное слово.

+0

С вашей помощью и некоторыми настройками он работает. Спасибо! – hugocarlmartin

Смежные вопросы