gpt4 book ai didi

swift - QUIZ 应用程序... UIAlertController 没有出现并且没有重新启动回到最初的问题

转载 作者:行者123 更新时间:2023-11-30 10:34:21 27 4
gpt4 key购买 nike

我认为 nextQuestion() 和 startOver() 函数给我带来了麻烦......当我浏览问题时,它会结束并且不会在屏幕上弹出警报必须点击 True 或 false ,然后它会 startOver() 但随后它会跳过第一个问题并直接进入第二个问题

导入UIKit

ViewController 类:UIViewController {

//Place your instance variables here
let allQuestions = QuestionBank()
var pickedAnswer : Bool = false
var questionNumber : Int = 0

@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet var progressBar: UIView!
@IBOutlet weak var progressLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

let firstQuestion = allQuestions.list[0]
questionLabel.text = firstQuestion.questionText
//when app loads it will display the first question in the array of question bank
}


@IBAction func answerPressed(_ sender: AnyObject) {
if sender.tag == 1 {
pickedAnswer = true
}
else if sender.tag == 2 {
pickedAnswer = false
}
//above - will change the picked answer based on which tag # is pressed
checkAnswer()

questionNumber = questionNumber + 1

nextQuestion()

}


func updateUI() {

}


func nextQuestion() {

if questionNumber <= 12 {
questionLabel.text = allQuestions.list[questionNumber].questionText
//if the current questionNumber is equal to or less than 12 then it will change the display text to the current question
}
else {

let alert = UIAlertController(title: "Congrats!", message: "Do you want to restart?", preferredStyle: .alert)

let restartAction = UIAlertAction(title: "Restart", style: .default, handler: { UIAlertAction in
self.startOver()
})

alert.addAction(restartAction)

present(alert, animated: true, completion: nil)


}
}


func checkAnswer() {

let correctAnswer = allQuestions.list[questionNumber].answer

if correctAnswer == pickedAnswer {
print("You got it!")
}
else {
print("Wrong!")
}
}


func startOver() {
questionNumber = 0
nextQuestion()
}

}

最佳答案

这是一个固件问题。刚刚更新到最新的 IOS 13 更新,模拟器运行应用程序没有任何问题,所以我相信我的固件是最新的,而 Xcode 是上一个版本。它在模拟器上运行没有问题。 13.1.1 上的模拟器和我刚刚上传到 13.1.3 的模拟器是唯一的区别。我已经查看了类(class)中完成的应用程序,除了固件之外,它的所有行都相同。 app running on Xcode simulator

关于swift - QUIZ 应用程序... UIAlertController 没有出现并且没有重新启动回到最初的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58404120/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com