[英]IOS: handle Cell Click Event with ScrollView in the cell
I have a customized UITableViewCell
, and in the cell, there is a UIScrollView
, If I set User Interactive to True for UIScrollView
, UIScrollView
can work but the cell Click Event could not be handled, and if I set User Interactive to False for UIScrollView
, cell can catch the Click event. 我有一个自定义UITableViewCell
,并在单元格,有一个UIScrollView
,如果我设置的用户互动为True UIScrollView
, UIScrollView
可以工作,但电池Click事件无法处理,如果我设置的用户互动为False UIScrollView
,单元格可以捕获Click事件。 Now I want to both UIScrollView
and cell click are handled, how to do that? 现在我要同时处理UIScrollView
和单元格单击,该怎么办?
Add a tap gesture on UIScrollView
. 在UIScrollView
上添加轻击手势。
UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)];
recognizer.umberOfTapsRequired = 1;
yourScrollView.userInteractionEnabled = YES;
[yourScrollView addGestureRecognizer:recognizer];
Add above code where you are setting up a cell. 在要设置单元的位置添加上述代码。 For example in cellForRowAtIndexPath:
method. 例如在cellForRowAtIndexPath:
方法中。 And handle the tap: 并处理水龙头:
-(void)handleTapGesture:(UITapGestureRecognizer *)sender
{
CGPoint location = [sender locationOfTouch:0 inView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:touchLocation];
// Handle tap.
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.