微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决我在UITableView的UITableViewCell中的UIViewController的视图中添加了UITapGestureRecognizer,为什么不触发?

| 标题很容易解释,但是我有一个UITableView,其中填充了自定义UITableViewCells。 在这自定义UITableViewCells内部,我添加显示自定义图像的自定义UIViewControllers。 在此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无法启动。我已经看了一个小时的代码,看不到我要去哪里了。 有人看到我想念的东西吗?还是他们以前遇到过这个?     

解决方法

        如果您试图在每个单元格上获得一个按钮,请参阅此处的操作说明。看一看。 iPhone SDK:使用专用按钮而不是通过点击单元格来打开单元格     ,        
UIImageView
对象的
userInteractionEnabled
默认设置为
NO
。这里也可能是这种情况。加
self.imageView.userInteractionEnabled = YES;
到您在问题中提出的
viewDidLoad
方法。     ,        
- (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;
}
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。