Posts

Post marked as solved
2 Replies
892 Views
The keyboard is not a problem, but will not dismiss when the app is loaded onto a real phone. In line 21 below we tried resignFirstResponder(), but it did not work. We are unsure on where to put the line to resignFirstResponder(). Any help you can provide is appreciated. @IBOutlet weak var textField: UITextField! @IBOutlet weak var countryImage: UIImageView! @IBOutlet weak var correctionLabel: UILabel! @IBOutlet weak var scoreLabel: UILabel! @IBOutlet weak var countryLinks: UIButton! @IBAction func countryLinksPressed(_ sender: UIButton) { if let url = URL(string: "\(questions[questionNumber].countryLink)") { UIApplication.shared.open(url, options: [:]) } } var questionNumber = 0 var score = 0 var response = "" @IBOutlet weak var submitButton: UIButton! @IBAction func submitButtonPressed(_ sender: Any) { response = textField.text! //line below causes a crash //textField.resignFirstResponder() if (response.lowercased() == questions[questionNumber].correctAnswer) { score += 1 scoreLabel.text = "Score: \(score)" correctionLabel.text = "Correct" correctionLabel.textColor = UIColor.green } else { correctionLabel.text = "Incorrect" correctionLabel.textColor = UIColor.red } if (questionNumber + 1 == questions.count) { endQuiz() } }
Posted Last updated
.