touchesBegan 不能在 UITableView 上工作 [英] touchesBegan not working on UITableView

查看:37
本文介绍了touchesBegan 不能在 UITableView 上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在全屏上有 UITableView.我想知道的是找到我点击单元格的位置.

I have UITableView over the full screen. What I would like to know is to find the location where I clicked a cell.

我想要做的是在单击任何单元格时显示复制选项.

What I want to do is to show the copy option when any cell is clicked.

为此我试过了

- (void) touchesEnded:(NSSet *)touches
withEvent:(UIEvent *)event {
    //some code
}

但是这个方法没有被调用.

but this method is not getting called.

知道如何在 UITableView

推荐答案

如果您只想在单击任何单元格时显示 Copy 选项,那么您必须去

if you just want to show Copy option when any cell is clicked then you have to go for

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

tableView 的方法.无需使用Touch event.

method of tableView. there is no need to use Touch event.

使用此方法,您可以使用 indexPath 获取所选单元格的副本.

Using this method you can get the copy of selected cell using indexPath.

要获取所选单元格的位置,您可以使用 rectForRowAtIndexPath 方法

To get the position of selected cell you can use rectForRowAtIndexPath method

CGRect rectInTableView = [tableView rectForRowAtIndexPath:indexPath];

编辑 2

CGRect rectInSuperview = [tableView convertRect:rectInTableView toView:[tableView superview]];

这篇关于touchesBegan 不能在 UITableView 上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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