I am going to work on a project that will use a lot of checkboxes. I found a solution like below, but I know this not right way.
@IBAction func btn_box(sender:
Instead of checking each and every button, just use a generic way to handle this. Set all your button to the same IBAction method and implement that like:
@IBAction func btn_box(sender: UIButton)
{
// Instead of specifying each button we are just using the sender (button that invoked) the method
if (sender.selected == true)
{
sender.setBackgroundImage(UIImage(named: "box"), forState: UIControlState.Normal)
sender.selected = false;
}
else
{
sender.setBackgroundImage(UIImage(named: "checkBox"), forState: UIControlState.Normal)
sender.selected = true;
}
}