我在 UITableView 中的 UITableViewCell 中的 UIViewController 视图中添加了一个 UITapGestureRecognizer,为什么它不会触发?

发布于 2024-11-16 21:43:08 字数 863 浏览 6 评论 0原文

标题非常具有解释性,但我有一个 UITableView,我正在用自定义 UITableViewCell 填充它。

在这些自定义 UITableViewCell 内部,我添加了显示自定义图像的自定义 UIViewController。

对于此 UIViewController 的 UIView,我添加了一个 UITapGestureRecognizer,如下所示:

- (void)viewDidLoad {
[super viewDidLoad];

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self 
                                                                             action:@selector(handleTap:)];
recognizer.numberOfTapsRequired = 1;
recognizer.delegate = self;
[self.imageView addGestureRecognizer:recognizer];

[recognizer release];
}

-(void)handleTap:(UITapGestureRecognizer *)sender{
NSLog(@"Handling tap on ArticleTileViewController");
}

当我运行应用程序时,单元格填充图像很好,但是当我点击图像(或自定义 UIViewController)时,没有任何反应!我的 NSLog 不会触发。我已经检查了一个小时的代码,但不知道哪里出错了。

有人看到我缺少的东西吗?或者他们以前遇到过这种情况吗?

The title is pretty explanatory, but I have a UITableView that I am populating with custom UITableViewCells.

Inside of these custom UITableViewCells, I am adding custom UIViewControllers that display custom images.

To this UIViewController's UIView, I am adding a UITapGestureRecognizer as follows:

- (void)viewDidLoad {
[super viewDidLoad];

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self 
                                                                             action:@selector(handleTap:)];
recognizer.numberOfTapsRequired = 1;
recognizer.delegate = self;
[self.imageView addGestureRecognizer:recognizer];

[recognizer release];
}

-(void)handleTap:(UITapGestureRecognizer *)sender{
NSLog(@"Handling tap on ArticleTileViewController");
}

When I run the app, the cells are populating the images great, but when I tap on the image(or the custom UIViewController), nothing happens! My NSLog won't fire. I have looked over the code for an hour now, and don't see where I am going wrong.

Does anybody see something I'm missing? Or have they run into this before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忆悲凉 2024-11-23 21:43:08

默认情况下,UIImageView 对象的 userInteractionEnabled 设置为 NO。这里也可能是这种情况。添加

self.imageView.userInteractionEnabled = YES;

到您在问题中提出的 viewDidLoad 方法。

UIImageView objects have their userInteractionEnabled set to NO by default. This might be the case here as well. Add

self.imageView.userInteractionEnabled = YES;

to the viewDidLoad method that you've presented in the question.

碍人泪离人颜 2024-11-23 21:43:08

如果您想在每个单元格上获得一个按钮,这里有一篇关于如何做到这一点的文章。看看吧。
iPhone SDK :使用专用按钮打开单元格,而不是通过单元格点击

If you are trying to get a button on each cell, here is a post on how to do it. Take a look.
iPhone SDK: Opening a cell with a dedicated button, not by cell tapping

你不是我要的菜∠ 2024-11-23 21:43:08
- (void)viewDidLoad {
       UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)] autorelease];
       gesture.delegate = self;
       [myWebView addGestureRecognizer:gesture];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
      return YES;
}
- (void)viewDidLoad {
       UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)] autorelease];
       gesture.delegate = self;
       [myWebView addGestureRecognizer:gesture];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
      return YES;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文