jeudi 14 décembre 2017

Using checkboxes in Swift

I am trying to figure out how to get the value of only the checkboxes that have been selected. I will have about ten more checkboxes with a Submit UIButton. When the Submit button is pressed I will be saving all the values for only the selected checkmarks. The code I have now will not print "Boxing and Karate" it only will print "Boxing" when Boxing is selected. screenshot

class SignUpSecondViewController: UIViewController, BEMCheckBoxDelegate {


@IBOutlet weak var wrestling: BEMCheckBox!
@IBOutlet weak var karate: BEMCheckBox!
@IBOutlet weak var boxing: BEMCheckBox!

override func viewWillAppear(_ animated: Bool) {
    navigationController?.setNavigationBarHidden(false, animated: true)
}
override func viewDidLoad() {
    super.viewDidLoad()

    boxing.delegate = self
    karate.delegate = self
    wrestling.delegate = self

    // Do any additional setup after loading the view.
}

  func didTap(_ checkBox: BEMCheckBox) {

    if (checkBox.tag == 1 && checkBox.on){
        print("BOXING")
    }else if (checkBox.tag == 1 && checkBox.on) && (checkBox.tag == 2 && checkBox.on){
        print("Boxing and karate")

    }

}




Aucun commentaire:

Enregistrer un commentaire