samedi 26 septembre 2020

How to select one checkbox at a time in swift?

I have implemented four checkboxes. Now, I want to select one checkbox at a time and if there's other checkbox selected, I want it deselected at the same time.

This is what I've tried but it selects all the checkboxes.

@IBAction func checkboxTapped(_ sender:UIButton){               
     if (sender.isSelected == false){
          sender.setImage(UIImage(named: "selected"), for: UIControl.State.normal)
          sender.isSelected = true;

     } else {
          sender.setImage(UIImage(named: "unselected"), for: UIControl.State.normal)
          sender.isSelected = false;
     }
}

Here, I have given same IBAction connection to all the checkboxes.




Aucun commentaire:

Enregistrer un commentaire