我在 UITableView 中的 UITableViewCell 中的 UIViewController 视图中添加了一个 UITapGestureRecognizer,为什么它不会触发?
标题非常具有解释性,但我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
默认情况下,
UIImageView
对象的userInteractionEnabled
设置为NO
。这里也可能是这种情况。添加到您在问题中提出的
viewDidLoad
方法。UIImageView
objects have theiruserInteractionEnabled
set toNO
by default. This might be the case here as well. Addto the
viewDidLoad
method that you've presented in the question.如果您想在每个单元格上获得一个按钮,这里有一篇关于如何做到这一点的文章。看看吧。
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