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. 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
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
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 ).
Thank you Paulw11 For helping!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.