Swift 测验应用程序。。。UIAlertController没有出现,也没有重新启动到初始问题

Swift 测验应用程序。。。UIAlertController没有出现,也没有重新启动到初始问题,swift,uialertcontroller,uialertaction,Swift,Uialertcontroller,Uialertaction,我相信nextQuestion()和startOver()函数就是它给我带来麻烦的地方。。。当我浏览问题时,它会一直到最后,不会在屏幕上弹出警告,只需点击正确或错误的问题,然后它就会开始回答()但它会跳过第一个问题,直接进入第二个问题 导入UIKit 类ViewController:UIViewController{ //Place your instance variables here let allQuestions = QuestionBank() var pickedAnswer :

我相信nextQuestion()和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()
}
//将实例变量放在此处
让所有问题=问题库()
var pickedAnswer:Bool=false
变量编号:Int=0
@IBVAR问题标签:UILabel!
@IBOutlet弱var scoreLabel:UILabel!
@IBVAR进度条:UIView!
@IBLABEL:UILabel!
重写func viewDidLoad(){
super.viewDidLoad()
让firstQuestion=allQuestions.list[0]
questionLabel.text=firstQuestion.questionText
//当应用程序加载时,它将显示问题库数组中的第一个问题
}
@iAction func answerPressed(\uSender:AnyObject){
如果sender.tag==1{
pickedAnswer=true
}
如果sender.tag==2,则为else{
pickedAnswer=错误
}
//上图-将根据按下的标签更改选择的答案
核对答案()
问题编号=问题编号+1
下一个问题()
}
func updateUI(){
}
func nextQuestion(){

如果questionNumber是固件问题。刚刚更新到最新的IOS 13更新,模拟器运行的应用程序没有问题,所以我相信我的固件是最新的,而之前的Xcode是最新的。它在模拟器上没有问题。13.1.1上的模拟器和我刚刚上传到13.1.3的模拟器是唯一的区别。我已经查看了课程中已完成的应用程序及其除固件外的所有行对行相同