如何使用uiview和uibutton检测Uitableview单元格? [英] How to detect tap on Uitableview cell with uiview and uibutton?

查看:90
本文介绍了如何使用uiview和uibutton检测Uitableview单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个表格视图,我将自定义uiview添加到单元格的内容视图中。
uiview有一个uibutton。但是,我可以在创建单元格时将uibutton添加到内容视图中。

I have created a table view and i am adding my custom uiview into the cell's content view. The uiview has a uibutton. However i can add the uibutton into the content view when the cell is created.

我想在tableview上获取tap事件以执行某些操作。我还想在uibutton上点击事件来执行不同的操作。

I want to get the tap event on the tableview to perform some action. I also want tap event on the uibutton to perform a different action.

问题是当我点击一行时按钮也被按下并触发两个事件。
我如何谨慎地获得这两个事件?即,当点击uibuttons边界外的单元格的部分时,点击tableview单元格。

The problem is when i tap a row the button is also getting pressed and two events are triggered. How can i get both the events discreetly? i.e tap on the tableview cell when portion the cell outside the uibuttons boundary is clicked.

推荐答案

您可以在单元格中添加一个Button as

You can add a Button in cell in as

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake( 13.0f, 13.0f, 90.0f, 90.0f)];
[button addTarget:self action:@selector(BtnPressed) forControlEvents:UIControlEventTouchUpInside];
[cellView.contentView addSubview:button];

然后你可以分别获得活动

then you can get events separately

这篇关于如何使用uiview和uibutton检测Uitableview单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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