双击 UITableViewCell [英] Double Tap on UITableViewCell

查看:24
本文介绍了双击 UITableViewCell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 UITableViewCell 上单击和双击.我为 UITableview 创建了一个 customDataSource.

I want to get a single tap as well as double tap on a UITableViewCell. I have created a customDataSource for the UITableview.

我怎样才能做到这一点?

How can I achieve this ?

推荐答案

正确的做法是在 tableView 上添加你的 UITapGestureRecognizer :

The correct way to do this is to add your UITapGestureRecognizer on the 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];

然后在您的回调方法中,您会找到具有以下内容的单元格:

Then in your callback methods you find the cell with something like this :

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

这篇关于双击 UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆