我想要单击和双击UITableViewCell
。我已经为UITableview
.
我怎样才能做到这一点?
正确的方法是将 UITapGestureRecognizer 添加到 tableView 上:
UITapGestureRecognizer* doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(doubleTap:)];
doubleTap.numberOfTapsRequired = 2;
doubleTap.numberOfTouchesRequired = 1;
[self.tableView addGestureRecognizer:doubleTap];
UITapGestureRecognizer* singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTap:)];
singleTap.numberOfTapsRequired = 1;
singleTap.numberOfTouchesRequired = 1;
[singleTap requireGestureRecognizerToFail:doubleTap];
[self.tableView addGestureRecognizer:singleTap];
然后在回调方法中,您会找到具有如下内容的单元格:
-(void)singleTap:(UITapGestureRecognizer*)tap
{
if (UIGestureRecognizerStateEnded == tap.state)
{
CGPoint p = [tap locationInView:tap.view];
NSIndexPath* indexPath = [_tableView indexPathForRowAtPoint:p];
UITableViewCell* cell = [_tableView cellForRowAtIndexPath:indexPath];
// Do your stuff
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)