1

My Storyboardこんにちは、プログラミングは初めてですが、事実を表示してトピックを教え、最後にクイズを行う IOS アプリケーションを作成しようとしています。これにはいくつかの複数のView Controllerが最適であり、トピックごとにView Controllerがあり、次にクイズごとにView Controllerがあると思いました。(それは正しい方法ですか?)

ボタンをクリックしたときにデータファイルから一連の事実を迅速に(ランダムなもののみ)順番に実行する方法がわからないため、事実の部分はまだ開始していません(最善の解決策が何であるかはわかりませんこれ?)。教育パートの後のクイズ用の3番目のView Controllerで、それを実装して2番目のView Controllerからボタンを介してアクセスしようとしましたが、2番目のView Controllerにうまく乗り込み、ナビゲーションバーから戻りましたが、勝ちました3 番目のビュー コントローラー (クイズがオンになっている) にアクセスさせないでください。ロードしようとすると、クラッシュしてデバッグ画面に移動します。どんな助けでも大歓迎です。1つをソートしたら、他のものを簡単に実行できるはずです。

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

// 著作権 © 2017 Adam Brooke. 全著作権所有。///

UIKitのインポート

class 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