I use a func textFieldShouldReturn that depending on what Integer I have in the textField it will either display an x or a check. I have 3 textFields but the func only works for numAnswerOne. How do I make it work for all 3 textFields?
Code Block func textFieldShouldReturn(_ textField: UITextField) -> Bool { //makes a return key work textField.resignFirstResponder() let text = textField.text let numAnswerOne = Int(answerOne.text!) let numAnswerTwo = Int(answerTwo.text!) let numAnswerThree = Double(answerThree.text!) if numAnswerOne == 70 { checkOne.alpha = 1 wrongOne.alpha = 0 answerOne.isUserInteractionEnabled = false } else if numAnswerOne != 70 { wrongOne.alpha = 1 //function stops here } else if numAnswerTwo == 2 { checkTwo.alpha = 1 wrongTwo.alpha = 0 answerTwo.isUserInteractionEnabled = false } else if numAnswerTwo != 2 { wrongTwo.alpha = 1 } else if numAnswerThree == 30.1 { checkThree.alpha = 1 checkThree.alpha = 0 checkThree.isUserInteractionEnabled = false } else if numAnswerThree != 30.1 { checkThree.alpha = 0 } return true }
Please show what your code is exactly now.
Are you sure you have defined the tags in Interface Builder as 1, 2, 3, to match the code ?
May be you just forgot to set it for numAnswerThree.
To understand what's going on, add a print after each test, such as:
If that works, don't forget to mark the correct answer.
If not, please report with the print results.
Are you sure you have defined the tags in Interface Builder as 1, 2, 3, to match the code ?
May be you just forgot to set it for numAnswerThree.
To understand what's going on, add a print after each test, such as:
Code Block if textField.tag == 1 { print("numAnswerOne") // continue
If that works, don't forget to mark the correct answer.
If not, please report with the print results.