【发布时间】:2017-07-10 21:25:40
【问题描述】:
【问题讨论】:
-
您想要多选或单选按钮。
-
我将使用多选按钮。
-
您应该创建一个自定义的 uitableviewcell 并在其中添加按钮并在 tablecell 内创建一个委托,当点击按钮时,调用该委托方法
标签: ios uitableview swift3 tableview
【问题讨论】:
标签: ios uitableview swift3 tableview
创建自定义单元格
在 UItableview 方法的cellForRowAt indexPath 内写下面的代码
cell.buttonname?.addTarget(self, action: #selector(self.buttonmethod), for: .touchUpInside)
cell.buttonname.tag = indexPath.section
//按钮点击方法
func buttonmethod(_ button: UIButton) {
print(button.tag)
// perform some action
}
【讨论】:
创建一个出口动作:并使用此代码找到索引路径
@IBAction func memberPicTapped(_ sender:UIButton) {
var superView = sender.superview
while !(superView is UITableViewCell) {
superView = superView?.superview
}
let cell = superView as! UITableViewCell
if let indexpath = YourTableView.indexPath(for: cell){
}
}
【讨论】: