[英]How to pass touched label text to gesture recognizer selector method
我有一個UITableView,並且正在為單元格使用UITableViewCell類。 在單元格內部,我使用標簽來顯示公司數據。
我需要的是在用戶單擊公司標題時在瀏覽器中打開公司網站,或者在用戶單擊顯示的電子郵件地址時打開郵件應用程序(但是當用戶觸摸單元格的其他任何部分時都不會發生任何事情)。
除了一件“小”事情,我在技術上一切正常(手勢識別器,打開野生動物園和郵件等)。 我不知道如何將這些網址(網絡或電子郵件)傳遞給touchrecognizer選擇器方法。
有任何想法嗎?
我認為您可以在表格視圖中獲取水龍頭位置,並進一步獲取該位置的indexPath。
- (void) handleGestureRecognizer:(UIGestureRecognizer *)recognizer {
CGPoint tapPoint = [recognizer locationInView:self.tableView];
NSIndexPath * indexPath = [self.tableView indexPathForRowAtPoint:self.tableView];
// Do whatever you want with indexPath.section, indexPath.row information
}
- (void)tapAction:(UITapGestureRecognizer *)tap {
UILabel *currentLabel = (UILabel *) tap.view;
NSString *labelText= currentLabel.text;
}
您可以嘗試一下。。這對我有用!!
由於您的數據是靜態的,因此可以在公司標題標簽上放置一個不可見的按鈕。
並在操作中給每個等於rowAtIndexPath的按鈕添加一個標記。
這是您的int tag = button.tag;
現在,如果您以數組形式獲取網站鏈接,則:
在按鈕操作中,將鏈接提取為
NSString *urlString=[websteArray objectAtIndex:tag];
OR
NSString *urlString=[NSString stringWithFormat:@"http://%@",[websteArray objectAtIndex:indexPath.row]];
NSLog(@"the strurl is %@",urlString);
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.