我的应用程序具有自定义的UITableView。在其cellForRowAtIndexPathUIViewController委托(delegate)方法中,我将包含多个自定义UILabel(实际上是UITableViewCell的子类)的自定义OHAttributedLabel对象实例化为内容 View 的 subview 。

我尝试在标签上设置userInteractionEnabled = YES,然后在 View Controller 中添加触摸事件,但这不起作用。

有想法吗?

谢谢

最佳答案

- (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
     }
}

或者
UILabel *label = =[UILabel alloc]init];
label.userInteractionEnabled = YES;
UITapGestureRecognizer *tapGesture =
[[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(labelTap)]     autorelease];
[label addGestureRecognizer:tapGesture];

关于iphone - 如何处理UILabel上的触摸事件作为UITableViewCell的 subview ?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7059416/

10-09 16:20
查看更多