I added the data to the table view, and I manually added “select all” to the list in the first position now that the user selects the first option, which selects everything, and then all the elements in the list should be selected and deselected when you select one and the same same, I tried the code below, but it doesn’t work, so someone can help me solve this problem.
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = ObjTableview.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! SelectUserCell
for i in 0 ..< self.getStudentName.count {
cell.btnCheckbox.setImage(UIImage(named: "selectedItem"), for: .normal)
print (i)
}
}
var unchecked = true
@IBAction func btnCheckBoxClick(_ sender: Any) {
if unchecked == true {
cell?.btnCheckbox.setImage(UIImage(named: "selectedItem"), for: .normal)
let cello = ObjTableview.cellForRow(at: indexPath!)
print(cello!)
ObjTableview.reloadData()
}else
{
cell?.btnCheckbox.setImage(UIImage(named: "unSelectedItem"), for: .normal)
}
}
source
share