My Storyboard Hi I'm new to programming but I'm trying to create an IOS application where I display facts and teach a topic and then at the end do a Quiz. I thought several multiple view controllers would be best for this and have a view controller for each topic then a view controller for each quiz. (Is that the right way of doing it?)
I haven't started on the facts part yet as I don't know how to run a series of facts in order from a data file in swift (Only random ones) when clicking a button, (any idea what the best solution is for this?). On the third view controller which is for my quiz after the teaching part, I tried to implement it and access it through a button from the 2nd view controller, it got onto the 2nd view controller fine and went back from the navigation bar however it won't let me access the third view controller (which my quiz is on) and when it tries to load up it crashes and goes to the debugging screen. Any help would be Greatly appreciated. As Once I've got one sorted should be easier doing the others.
`// BasicsQuizViewController.swift
// Java Fun; Learning How To Code
//
// Created by Adam Brooke on 30/03/2017.
// Copyright © 2017 Adam Brooke. All rights reserved. //
import 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.
}
*/