gpt4 book ai didi

ios - 如何在 tableView 单元格上获取点击事件 UIbutton?

转载 作者:行者123 更新时间:2023-11-28 13:11:42 28 4
gpt4 key购买 nike

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

这怎么可能?

最佳答案

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

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")
}
}

关于ios - 如何在 tableView 单元格上获取点击事件 UIbutton?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31048504/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com