2012-06-28 76 views
0

我已经尝试通过互联网搜索有关此问题,但无法拿出解决方案来解决我的问题。在iOS中的UITableviewCell的子视图中触摸滚动视图的事件

我必须做的UITableViewCell一个子类中,我加入UIScrollView作为一个子视图,现在我想滚动手势由scrolView被倾听并单击手势由UItableView听着。
也是用这个布局是针对苹果的HIG

+0

参见[UIScrollView的内部的UITableViewCell触摸检测](http://stackoverflow.com/questions/6636844/uiscrollview-inside-uitableviewcell-touch-detect)链路它显示触摸检测 –

+0

最好是可以添加单敲击手势到viewDidLoad中的tableview。 –

回答

0

如果滚动视图为表视图的一个子视图,可以捕捉手势,并将其发送到它的父视图这样的:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
    { 
     [self.nextResponder touchesBegan:touches withEvent:event]; 
    } 
2

这是一个老问题,但由于我没有真正找到一个好的答案,我想我会提供一个。这种方法捕获UIScrollView(包含在表格单元内)和tap事件直接在UITableView单元上的tap事件,并将它们传递给UITableViewDelegate。它也允许你滚动你的UIScrollView内容而不需要传递滚动事件。不需要任何子类。

  1. 在viewDidLoad中,实例化一个UITapGestureRecognizer上的UITableView
// Capture taps on scrollView fields and pass along to tableView 
let tap = UITapGestureRecognizer(target: self, action: "tapIntercept:") 
tableView.addGestureRecognizer(tap) 
  • 上面
  • 选择创建一个回调函数
    // Get the location of the table cell beneath the scrollView and pass the event off to the tableView 
    func tapIntercept(recognizer: UIGestureRecognizer) { 
        let point = recognizer.locationInView(tableView) 
        if let indexPath = tableView.indexPathForRowAtPoint(point) { 
         tableView(tableView, didSelectRowAtIndexPath: indexPath) 
        } 
    } 
    
    相关问题