【问题标题】:Cell Imageview with Gesture - Which image was tapped?带有手势的单元格图像视图 - 哪个图像被点击?
【发布时间】:2013-08-08 01:10:11
【问题描述】:

我有一个带有单元格的 UITableview,这些单元格用图像、labeltext 和 detailTextLabel 显示。 cell.imageview 配置了一个 UITapGestureRecognizer:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(infoImageTapped:)];
[tap setNumberOfTapsRequired:1];
[cell.imageView setGestureRecognizers:[NSArray arrayWithObject:tap]];

“infoImageTapped”方法触发良好。现在我想知道点击了哪个图像(更具体地说,是哪个 imageNamed)。

我尝试了以下代码:

UIImageView *theTappedImageView = (UIImageView *)tap.view;
NSLog(@"Gesture Tag: %@", theTappedImageView.description);

在 NSLog-Window 中:显示 imageNamed (*.png) 但我不知道如何将这些信息写入 一个 NSString 变量。

我需要命名的图像(或单元格中原始图像的引用)来打开带有图像的 AlertView。

提前致谢 弗洛里安

【问题讨论】:

  • theTappedImageView.image 应该为您提供图像视图中设置的图像。这就是你要找的吗?
  • 天啊。我发誓我已经试过了。谢谢@Amar,效果很好!
  • @FlorianThürkow 看看我的回答

标签: iphone uitableview imageview uitapgesturerecognizer


【解决方案1】:
-(void)infoImageTapped :(UITapGestureRecognizer *)gesture
{
    UIImageView *image = (UIImageView *) gesture.view;
   NSLog(@"Gesture Tag: %@", image.description);

}

希望它对你有用:)

【讨论】:

  • 谢谢@Rushabh :-) 我试过了,但我第一次没有工作。无论如何,现在它就像魅力一样 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-02
相关资源
最近更新 更多