如何获取tableView单元格上的单击事件UIbutton? [英] How to get click event UIbutton on tableView cell?

查看:57
本文介绍了如何获取tableView单元格上的单击事件UIbutton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 TableViewCell 上使用了 UIbutton ,但是当我单击一行时,只有该行被单击,但是我只想单击该行上的按钮.

I have taken UIbutton on TableViewCell, but when I click on a row, only the row get clicked, but I want to click only the button on that row.

这怎么可能?

推荐答案

在CellForRowatindexPath中为按钮定义标签,并将目标设置为处理事件

In the CellForRowatindexPath define tag for button and also set target to handler the event

button.tag=indexPath.row;
button.addTarget(self, action: "buttonHandler:", forControlEvents: UIControlEvents.TouchUpInside)

*************
func buttonHandler(sender:UIButton!)
{
    if(sender.tag==0){
         println("Button at row 0")
    }
    else if(sender.tag==1){
       println("Button at row 1")
    }
}

这篇关于如何获取tableView单元格上的单击事件UIbutton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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