如何获取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")
    }
}