1

我的故事板嗨,我是编程新手,但我正在尝试创建一个 IOS 应用程序,在其中显示事实并教授一个主题,然后最后做一个测验。我认为几个多视图控制器最适合这个,每个主题都有一个视图控制器,然后每个测验都有一个视图控制器。(这是正确的做法吗?)

我还没有开始事实部分,因为我不知道如何在单击按钮时从数据文件中按顺序运行一系列事实(只有随机的),(知道最好的解决方案是什么这个?)。在教学部分之后用于我的测验的第三个视图控制器上,我尝试实现它并通过第二个视图控制器的按钮访问它,它很好地进入第二个视图控制器并从导航栏返回但是它赢了'不要让我访问第三个视图控制器(我的测验正在进行),当它尝试加载时它崩溃并进入调试屏幕。任何帮助将不胜感激。因为一旦我得到一个排序应该更容易做其他人。

    `//  BasicsQuizViewController.swift
    //  Java Fun; Learning How To Code
    //
    //  Created by Adam Brooke on 30/03/2017.

// 版权所有 © 2017 亚当布鲁克。版权所有。//

导入 UIKit

类 BasicsQuizViewController: UIViewController {

@IBOutlet weak var QuestionLabel: UILabel!
@IBOutlet weak var Button1: UIButton!
@IBOutlet weak var Button2: UIButton!
@IBOutlet weak var Button3: UIButton!
@IBOutlet weak var Button4: UIButton!

var CorrectAnswer = String()

override func viewDidLoad() {
    super.viewDidLoad()

    RandomQuestions()

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

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func RandomQuestions(){
    var RandomNumber = arc4random() % 4
    RandomNumber += 1

    switch(RandomNumber){

    case 1:
        QuestionLabel.text = "Hello World, What i My Name?"
        Button1.setTitle("John", for: UIControlState.normal)
        Button2.setTitle("Boo", for: UIControlState.normal)
        Button3.setTitle("Adam", for: UIControlState.normal)
        Button4.setTitle("Bill", for: UIControlState.normal)
        CorrectAnswer = "2"
        break
    case 2:
        QuestionLabel.text = "What would you like for tea?"
        Button1.setTitle("Curry", for: UIControlState.normal)
        Button2.setTitle("Hot Dog", for: UIControlState.normal)
        Button3.setTitle("Poo", for: UIControlState.normal)
        Button4.setTitle("Mc D's", for: UIControlState.normal)
        CorrectAnswer = "4"

        break
    case 3:
        QuestionLabel.text = "Are you Gay?"
        Button1.setTitle("Yeah", for: UIControlState.normal)
        Button2.setTitle("No", for: UIControlState.normal)
        Button3.setTitle("Maybe", for: UIControlState.normal)
        Button4.setTitle("A Little", for: UIControlState.normal)
        CorrectAnswer = "2"

        break
    case 4:
        QuestionLabel.text = "What sport do you like?"
        Button1.setTitle("Football", for: UIControlState.normal)
        Button2.setTitle("Rugby", for: UIControlState.normal)
        Button3.setTitle("Tennis", for: UIControlState.normal)
        Button4.setTitle("Golf", for: UIControlState.normal)
        CorrectAnswer = "1"

        break
    default:

        break
    }

}


@IBAction func Button1Action(_ sender: Any) {
    if (CorrectAnswer == "1"){

    NSLog("Correct")
}
else{
    NSLog("Sorry You are Wrong")
    }
}
@IBAction func Button2Action(_ sender: Any) {
    if (CorrectAnswer == "2"){

    NSLog("Correct")
}
else{
    NSLog("Sorry You are Wrong")
    }
}

@IBAction func Button3Action(_ sender: Any) {
    if (CorrectAnswer == "3"){

    NSLog("Correct")
}
    else{
        NSLog("Sorry You are Wrong")
    }
}

@IBAction func Button4Action(_ sender: Any) {
    if (CorrectAnswer == "4"){

    NSLog("Correct")
}
    else{
        NSLog("Sorry You are Wrong")
    }
}


/*
// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
}
*/

错误 1

4

0 回答 0