[英]Checkbox Issue in tableview cell
I have a multiple checkbox in tableview cell and total number of cell 4,i want to select one checkbox at one time and all check box is unselect if i select any one of check box and also one button in table view cell button are also disable of other cell so how i implement this logic.我在表格视图单元格中有一个多个复选框,单元格总数为 4,我想一次 select 一个复选框,如果我 select 任何一个复选框和表格视图单元格按钮中的一个按钮也被禁用,则所有复选框都未选中其他单元格,所以我如何实现这个逻辑。 here i implement image check and uncheck logic在这里我实现图像检查和取消检查逻辑
func setupData(plansModel: [Plans], mainRowIndex: Int, selctedPlan: Int, isAllUnselected: Bool){
self.plansModel = plansModel
indexMain = mainRowIndex
selectedPlanId = selctedPlan
self.isAllUnselected = isAllUnselected
self.changePlanBtn.isHidden = isAllUnselected
priceTableView.reloadData()
}
i take this variable for data and manage checkbox我将此变量用于数据并管理复选框
I think you want this我想你想要这个
You can do this Way!你可以这样做! Firts make a variable第一变数
var selectedIndex: IndexPath = IndexPath(row: 0, section: 0)
Second in tableview didselecte method add this在 tableview didselecte 方法的第二个添加这个
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let previousSelectedIndex = selectedIndex
selectedIndex = indexPath
checkBoxTableView.reloadRows(at: [previousSelectedIndex, selectedIndex], with: .none)
}
third and last add this code in tableview cellForRow Method第三个也是最后一个在 tableview cellForRow 方法中添加此代码
if selectedIndex.row == indexPath.row {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
I think your answer is solved.我想你的答案已经解决了。
This Was edited For realod only two row rather than whole tableview (this edit rafrence by paulw11 ).这仅针对 realod 两行而不是整个 tableview 进行了编辑(此编辑 rafrence 由paulw11 )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.