up 0 down

Я новичок в быстром и программировании в целом, и я пытаюсь сделать приложение викторины, и я хочу, чтобы приложение, чтобы перейти от начального экрана, в меню выбора с, а затем на экран викторины.

Проблема заключается в том, когда я нажимаю кнопку второй категории, это приводит меня к правильному контроллеру представления. Но это выводит одни и те же вопросы и ответы от первого массива. Я попытался сделать переменные и массивы частными, но которые до сих пор не работают.

Что я делаю неправильно?

> //StartScreen ViewContoller
    import UIKit

class ViewController: UIViewController {

    @IBAction func startButton(_ sender: Any) {
        self.performSegue(withIdentifier: "StartToMenuSegue", sender: self)
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
}


> //Menu ViewController
import UIKit

class MenuViewController: UIViewController {

    @IBAction func firstCategoryButton(_ sender: Any) {
        self.performSegue(withIdentifier: "MenuToQuestions1Segue", sender: self)

    }
    @IBAction func secondCategoryButton(_ sender: Any) {
         self.performSegue(withIdentifier: "MenuToQuestions2Segue", sender: self)
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
}


> //FirstCategoryQuestions
import UIKit

class Questions1ViewController: UIViewController {

        private let questions1 = [
           "Who created this app?", 
           "What was the 2017-2018 FBLA-PBL National Theme?", 
           "In what year did NYS FBLA recieve its National Charter?", 
           "Which of the following is a responsibility of ALL state officers?", 
           "One of the key responsibilites of the State Historian is:", 
           "Which of the following is a TRUE statement:"
        ]

        private let answers1 = [
           ["Abdullah Bismil", "Duncan Sheen", "Avinash Gagai", "Christian Pascal"], 
           ["Elevate Your Future", "A Legacy of Leadership", "Suit Up, Step Up",""], 
           ["1964", "1960", "1972", "1972"], 
           ["Compile and submit monthly correspondence", "Write and distribute the minutes of state officer meegins", "Plan and organize the Fall district meeting", ""], 
           ["Create and publish a State Annuel Report", "Evaluate state vice presidents at designated times", "Review all reimbursement requests", ""], 
           ["Only 3 candidates can run for any one election posistion", "Non-dues paying FBLA members are eligible to hold state office", "No approval is necessary for a FBLA member to run for state office", ""]
        ]

        //variables
        private var currentQestion1 = 0
        private var rightAnswerPlacement1: UInt32 = 0
        private var correct1 = 0
        private var incorrect1 = 0

        @IBOutlet weak var questionView: UILabel!

        @IBAction func answerButtons(_ sender: AnyObject) {
           if (sender.tag == Int(rightAnswerPlacement1)) {
              print ("CORRECT")
              correct1 += 1
           } else {
              print ("INCORRECT")
              incorrect1 += 1
           }

           if (currentQestion1 != questions1.count) {
              newQuestion1()
           } else if (currentQestion1 == questions1.count) {
              killCommand1()
           }
       }

       override func viewDidAppear(_ animated: Bool) {
          newQuestion1()
       }

       //function that displays new question
       func newQuestion1() {
          questionView.text = questions1[currentQestion1]

          rightAnswerPlacement1 = arc4random_uniform(4) + 1

          //create a button
          var button:UIButton = UIButton()

          var x = 1
          for i in 1...4 {
             //create a button
             button = view.viewWithTag(i) as! UIButton

             if (i == Int(rightAnswerPlacement1)) {
                button.setTitle(answers1[currentQestion1][0], for: .normal)
             } else {
                button.setTitle(answers1[currentQestion1][x], for: .normal)
                x += 1
             }
          }
          currentQestion1 += 1
       }

       func killCommand1() {
          self.performSegue(withIdentifier:"Questions1ToStartSegue", sender: self)
       }

       override func viewDidLoad() {
          super.viewDidLoad()
          // Do any additional setup after loading the view, typically from a nib.
       } 
}

> //Second Category ViewController
import UIKit

class Questions2ViewController: UIViewController {

    private let questions2 = ["Hello how Are you?", "What is my favorite color"]

    private let answers2 = [["Good", "Fine", "OK", "Eh"], ["Blue", "Green", "Red", "Purple"]]

   //variables
   private var currentQestion2 = 0
   private var rightAnswerPlacement2:UInt32 = 0
   private var correct2 = 0
   private var incorrect2 = 0

   @IBOutlet weak var questionView2: UILabel!  

   @IBAction func answerButtons2(_ sender: AnyObject) {
      if (sender.tag == Int(rightAnswerPlacement2)) {
         print ("CORRECT")
         correct2 += 1
      } else {
         print ("INCORRECT")
         incorrect2 += 1
      }

      if (currentQestion2 != questions2.count) {
         newQuestion2()
      } else if (currentQestion2 == questions2.count) {
         killCommand2()
      }
  }

  override func viewDidAppear(_ animated: Bool) {
     newQuestion2()
  }

  //function that displays new question
  func newQuestion2() {
     questionView2.text = questions2[currentQestion2]

     rightAnswerPlacement2 = arc4random_uniform(4) + 1

     //create a button
     var button: UIButton = UIButton()

     var x = 1
     for i in 1...4 {
        //create a button
        button = view.viewWithTag(i) as! UIButton

        if (i == Int(rightAnswerPlacement2)) {
           button.setTitle(answers2[currentQestion2][0], for: .normal)
        } else {
           button.setTitle(answers2[currentQestion2][x], for: .normal)
           x += 1
        }
     }
     currentQestion2 += 1
  }

  func killCommand2() {
     self.performSegue(withIdentifier:"Questions1ToStartSegue", sender: self)
  }

  override func viewDidLoad() {
     super.viewDidLoad()
     // Do any additional setup after loading the view, typically from a nib.
  }  

}