如何在UILabel上处理触摸事件作为UITableViewCell的子视图?

Bam*_*a91 8 iphone cocoa-touch objective-c uitableview ios

我的应用有自定义UITableView.在它的cellForRowAtIndexPath委托方法中,UIViewController我实例化UITableViewCell包含多个自定义UILabel(实际上是子类OHAttributedLabel)的自定义对象作为内容视图的子视图.

我尝试userInteractionEnabled = YES在标签上设置,然后在视图控制器中添加触摸事件,但这不起作用.

想法?

谢谢

Pra*_*n-K 13

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
      UITouch *touch = [[event allTouches] anyObject];
      if (CGRectContainsPoint([self.site frame], [touch locationInView:self.view])){
       //do whatever you want
     }
}
Run Code Online (Sandbox Code Playgroud)

要么

UILabel *label = =[UILabel alloc]init];
label.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)]     autorelease];
[label addGestureRecognizer:tapGesture];
Run Code Online (Sandbox Code Playgroud)