在UITapGestureRecognizer处理程序中获取tapped单元格 [英] Get tapped cell in UITapGestureRecognizer handler

查看:97
本文介绍了在UITapGestureRecognizer处理程序中获取tapped单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IOS5应用中为我的表格单元设置了一个手势识别器:

I have set up a gesture recognizer for my table cell in my IOS5 app:

UITapGestureRecognizer* oneFingerDoubleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(cellOneFingerDoubleTap:)];
oneFingerDoubleTap.numberOfTapsRequired = 2;
[cell addGestureRecognizer:oneFingerDoubleTap];

并实现了处理程序方法:

And implemented handler method:

- (void)cellOneFingerDoubleTap:(id) sender
{
    NSLog(@"taptap");
}

一切正常。我的问题是我无法通过窃听细胞传递细胞或其他一些数据。正如我所见(id)发送者是UITapGestureRecognizer本身。

It works fine. My problem is that I can not pass the cell was tapped or some other data with the tapped cell. As I see (id)sender is the UITapGestureRecognizer itself.

我的问题是:如何在处理程序方法(cellOneFingerDoubleTap)中获取tapped单元格?如何在处理程序方法中获取tapped单元格的索引?

My question is: how can I get the tapped cell in the handler method (cellOneFingerDoubleTap)? How can I get in the handler method the index of the tapped cell?

谢谢!

推荐答案

如果你从传递的手势识别器中获取视图在您的 cellOneFingerDoubleTap:方法中,然后您将获得已被点击的单元格。类似于:

If you grab the view from the gesture recogniser that is passed in to you on your cellOneFingerDoubleTap: method, then you'll get the cell that's been tapped. Something like:

- (void)cellOneFingerDoubleTap:(UIGestureRecognizer*)recognizer {
    UITableViewCell *cell = (UITableViewCell*)recognizer.view;
}

[我只假设一个单元格你的意思是 UITableViewCell 顺便说一下]

[I'm just assuming by a "cell" you mean a UITableViewCell by the way]

这篇关于在UITapGestureRecognizer处理程序中获取tapped单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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