0

我有一个 UITableView 并且我正在为单元格使用 UITableViewCell 类。在单元格内,我使用标签来显示公司数据。

我需要的是当用户点击公司标题时在浏览器中打开公司网站,或者当用户点击显示的电子邮件地址时打开邮件应用程序(但当用户触摸单元格的任何其他部分时不会发生任何事情)。

除了一件“小”事情外,我在技术上一切正常(手势识别器、打开 Safari 和邮件等)。我不知道如何将这些 url(网络或电子邮件)传递给 touchrecognizer 选择器方法。

有任何想法吗?

4

3 回答 3

4
- (void)tapAction:(UITapGestureRecognizer *)tap {
UILabel *currentLabel = (UILabel *) tap.view;
NSString *labelText= currentLabel.text;
   }

你可以试试这个..这对我有用!!

于 2012-11-26T07:03:19.177 回答
4

我认为您可以在表格视图中获取点击位置,并进一步获取该位置的 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
}
于 2012-10-06T19:01:04.887 回答
1

由于您的数据是静态的,您可以在公司标题标签上放置一个不可见的按钮。

并在动作中为每个按钮添加一个等于 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]];
于 2012-10-07T06:50:04.213 回答