I have 3 sections in my tableView
, I want single selection like radio buttons in each section. My code working for single section, but not for multiple sections. I'm not using any custom buttons for this, directly using contentView
imageView
to set images and didSelectRowAt indexPath:
for selection
My code is
cell?.imageView?.image = UIImage.init(named: "radio1")//Deselected state
cell?.imageView?.tag = indexPath.row
cell?.contentView.viewWithTag(8888)
if (selectedIndexPath != nil && selectedIndexPath?.section == 0 && selectedIndexPath?.row == indexPath.row) {
cell?.imageView?.image = UIImage.init(named: "radio2")//Selected state
} else {
cell?.imageView?.image = UIImage.init(named: "radio1")//Deselected state
}
if selectedIndexPath?.section == 1 {
}
if selectedIndexPath?.section == 2 {
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
selectedIndexPath = indexPath//Save selected indexpath
print(selectedIndexPath)
tblView.reloadData()
The above code getting result like
When I select (Section1, Row0) automatically (Section2, Row0)also selected. I want select rows individually based on sections.