2011-06-21 27 views
1

标题很好解释,但我有一个UITableView,我用自定义的UITableViewCells填充。我有一个UITapGestureRecognizer添加到UITableView中的UITableViewCell中的UIViewController的视图,为什么它不会触发?

在这些自定义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不会启动。我现在已经查看了一个小时的代码,并没有看到我出错的地方。

有人看到我失踪的东西吗?或者他们之前遇到过这种情况?

+0

我认为这将是最好有一个UIView或UIImageView的子类,而不是使用一个UIViewController的。除非你的视图太复杂了,否则最好是UIView而不是UIViewController。在你的情况下,只是显示一个自定义图像,它听起来是为UIImageView子类或甚至可能只是UIImageView而定制的。 –

回答

8

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

self.imageView.userInteractionEnabled = YES; 

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

+0

谢谢!在钱上! –

0
- (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; 

}

相关问题