This is one of the first pieces of code we made. In this example all questions and answers are placed in the same view controller:
//
// ViewController.swift
// FirstPrototype
//
// Created by UDI-ME-TA on 25/04/2015.
// Copyright (c) 2015 UDI-ME-TA. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet var ViewController: UIView!
@IBOutlet var question1: UILabel!
@IBOutlet var answer1: UIButton!
@IBOutlet var answer2: UIButton!
@IBOutlet var answer3: UIButton!
@IBOutlet var answer4: UIButton!
@IBOutlet var result: UILabel!
@IBOutlet var NextButton: UIButton!
var questionNumber: Int!
var group1 = [Int]()
var x: Int!
override func viewDidLoad() {
super.viewDidLoad()
self.chooseQuestion()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/* ////////////////////////////////___QUE PASSA AMB CADA RESPOSTA____/////////////////////////// */
/* ////////////////////////////////ADD POINTS +++ TELL HOW MANY POINTS/////////////////////////// */
// -1 RA- PRIMERA RESPOSTA DE TOTES LES PREGUNTES
@IBAction func answer1(sender: AnyObject) {
NextButton.hidden = false
if questionNumber == 0 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 1{
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 2 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 3 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}
}
// -2 NA- SEGONA RESPOSTA DE TOTES LES PREGUNTES
@IBAction func answer2(sender: AnyObject) {
NextButton.hidden = false
if questionNumber == 0 {
group1.append(2)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 1{
group1.append(2)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 2 {
group1.append(2)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 3 {
group1.append(2)
result.text="the points are \(group1.reduce(0,+))"
}
}
// -3 RA- TERCERA RESPOSTA DE TOTES LES PREGUNTES
@IBAction func answer3(sender: AnyObject) {
NextButton.hidden = false
if questionNumber == 0 {
group1.append(3)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 1{
group1.append(3)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 2 {
group1.append(3)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 3 {
group1.append(3)
result.text="the points are \(group1.reduce(0,+))"
}
}
// -4 TA- CUARTA RESPOSTA DE TOTES LES PREGUNTES
@IBAction func answer4(sender: AnyObject) {
NextButton.hidden = false
if questionNumber == 0 {
group1.append(4)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 1{
group1.append(4)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 2 {
group1.append(4)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 3 {
group1.append(4)
result.text="the points are \(group1.reduce(0,+))"
}
}
/* ///////////////////// ///////////NEXT___BUTON/////////////////////////// */
@IBAction func NextButton(sender: AnyObject) {
//fer que cuan premis el botó surti la seguent pregunta
// fent que el "questionNumber" incrementi per 1
for var x = 0; x < 3; ++x {
self.chooseQuestion()
}
NextButton.hidden = true
}
/* ////////////////////////////////QUESTIONS &&& ANSWERS ___ HOW IT LOOKS/////////////////////////// */
func chooseQuestion () {
questionNumber = Int(x)
switch questionNumber {
case 0:
question1.text = "first question"
answer1.setTitle("1 firt answer", forState: UIControlState.Normal)
answer2.setTitle("1 second answer", forState: UIControlState.Normal)
answer3.setTitle("1 third answer", forState: UIControlState.Normal)
answer4.setTitle("1 forth answer", forState: UIControlState.Normal)
case 1:
question1.text = "second question"
answer1.setTitle("2 first answer", forState: UIControlState.Normal)
answer2.setTitle("2 second answer", forState: UIControlState.Normal)
answer3.setTitle("2 third answer", forState: UIControlState.Normal)
answer4.setTitle("2 forth answer", forState: UIControlState.Normal)
case 2:
question1.text = "third question"
answer1.setTitle("3 first answer", forState: UIControlState.Normal)
answer2.setTitle("3 second answer", forState: UIControlState.Normal)
answer3.setTitle("3 third answer", forState: UIControlState.Normal)
answer4.setTitle("3 forth answer", forState: UIControlState.Normal)
case 3:
question1.text = "fourth question"
answer1.setTitle("4 first answer", forState: UIControlState.Normal)
answer2.setTitle("4 second answer", forState: UIControlState.Normal)
answer3.setTitle("4 third answer", forState: UIControlState.Normal)
answer4.setTitle("4 forth answer", forState: UIControlState.Normal)
default:
break
}
}
}
________
In this example we were creating the storyboard linking different view controllers, and also relating them with a file that would content the code of each one:
_______
In the next example, all the storyboard is created, although we hadn’t add the style yet:
At this stage we had already created almost all code for the app to function properly. Each view controller was related with its correspondent code:
ZonesViewController.swift
//
// var info : String? var info : String? ZonesViewController.swift
// MC_APP2
//
// Created by UDI-ME-TA on 01/05/2015.
// Copyright (c) 2015 UDI-ME-TA. All rights reserved.
//
import UIKit
class ZonesViewController: UIViewController {
var zonePicked : String = ""
var group1 = [Int]()
var group2 = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func zoneOne(sender: AnyObject) {
zonePicked = "zoneOne"
}
@IBAction func zoneTwo(sender: AnyObject) {
zonePicked = "zoneTwo"
}
@IBAction func zoneThree(sender: AnyObject) {
zonePicked = "zoneThree"
}
@IBAction func zoneFour(sender: AnyObject) {
zonePicked = "zoneFour"
}
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let destinationVC = segue.destinationViewController as? TestViewController {
destinationVC.zonePicked = zonePicked
destinationVC.group1 = group1
destinationVC.group2 = group2
}
performSegueWithIdentifier(zonePicked, sender: self)
}
override func performSegueWithIdentifier(identifier: String?, sender: AnyObject?) {
}
}
TestViewController.swift
//
// TestViewController.swift
// MC_APP2
//
// Created by UDI-ME-TA on 01/05/2015.
// Copyright (c) 2015 UDI-ME-TA. All rights reserved.
//
import UIKit
class TestViewController: UIViewController {
var zonePicked : String?
@IBOutlet var Question1: UILabel!
@IBOutlet var Question2: UILabel!
@IBOutlet var Question3: UILabel!
var group1 = [Int]()
var group2 = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
if zonePicked == "zoneOne"{
setupZoneOne()
}
if zonePicked == "zoneTwo"{
setupZoneTwo()
}
if zonePicked == "zoneThree"{
setupZoneThree()
}
if zonePicked == "zoneFour"{
setupZoneFour()
}
}
func setupZoneOne() {
Question1.text = "What shape is the entrance to the cloisters?"
Question2.text = "What is the arrangement of shapes in the arch of the cloisters?"
Question3.text = "What are shapes cut out in the armoured glove?"
}
func setupZoneTwo() {
Question1.text = "What is the shape on the points of the Cathedral roof during construction?"
Question2.text = "What is the shape of the font?"
Question3.text = "What is the shape of the freemason symbol given to Elias De Derham?"
}
func setupZoneThree() {
Question1.text = "What is the shape of the shield painted on the ceiling?"
Question2.text = "What shape is the arrangement of the Prisoners of Conscience Window?"
Question3.text = "What shape is the Shrine Tomb of St Osmund?"
}
func setupZoneFour() {
Question1.text = "What is the shape of the Chapter House?"
Question2.text = "What is the shape of the fleur-de-lis found on all the cushions?"
Question3.text = "What is the shape found on the pillow for Nicholas"
}
@IBAction func StartQuizButtonPopUp(sender: AnyObject) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let destinationVC = segue.destinationViewController as? MultichoiceViewController {
destinationVC.zonePicked = zonePicked
destinationVC.group1 = group1
destinationVC.group2 = group2
}
performSegueWithIdentifier(zonePicked, sender: self)
}
override func performSegueWithIdentifier(identifier: String?, sender: AnyObject?) {
}
}
MultichoiceViewController.swift (With a POPUP window)
//
// MultichoiceViewController.swift
// MC_APP2
//
// Created by UDI-ME-TA on 07/05/2015.
// Copyright (c) 2015 UDI-ME-TA. All rights reserved.
//
import UIKit
class MultichoiceViewController: UIViewController {
var zonePicked : String?
@IBOutlet var popUp: UIView!
@IBOutlet var QuestionText: UILabel!
@IBOutlet var answer1: UIButton!
@IBOutlet var answer2: UIButton!
@IBOutlet var answer3: UIButton!
@IBOutlet var answer4: UIButton!
@IBOutlet var result: UILabel!
@IBOutlet var nextButton: UIButton!
@IBOutlet var PopUp: UIView!
@IBOutlet var PopUpLabel: UILabel!
@IBOutlet var PopUpButto: UIButton!
var questionNumber = 0
var group1: [Int]!
var group2: [Int]!
override func viewDidLoad() {
super.viewDidLoad()
nextButton.hidden = true
popUp.hidden = false
if zonePicked == "zoneOne"{
self.chooseQuestion1()
}
else if zonePicked == "zoneTwo"{
self.chooseQuestion2()
}
else if zonePicked == "zoneThree"{
self.chooseQuestion3()
}
else {
self.chooseQuestion4()
}
// Do any additional setup after loading the view.
}
@IBAction func PopUpButton(sender: AnyObject) {
popUp.hidden = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func answer1pressed(sender: AnyObject) {
nextButton.hidden = false
if questionNumber == 0 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 1{
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 2 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}
}
@IBAction func answer2pressed(sender: AnyObject) {
nextButton.hidden = false
if questionNumber == 0 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 1{
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 2 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}
}
@IBAction func answer3pressed(sender: AnyObject) {
nextButton.hidden = false
if questionNumber == 0 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 1{
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 2 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}
}
@IBAction func answer4pressed(sender: AnyObject) {
nextButton.hidden = false
if questionNumber == 0 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 1{
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}else if questionNumber == 2 {
group1.append(1)
result.text="the points are \(group1.reduce(0,+))"
}
}
@IBAction func nextquestion(sender: AnyObject) {
if zonePicked == "zoneOne"{
self.chooseQuestion1()
}
else if zonePicked == "zoneTwo"{
self.chooseQuestion2()
}
else if zonePicked == "zoneThree"{
self.chooseQuestion3()
}
else {
self.chooseQuestion4()
}
nextButton.hidden = true
}
func chooseQuestion1 (){
switch questionNumber{
case 0:
QuestionText.text = "first question"
answer1.setTitle("first answer", forState: UIControlState.Normal)
answer2.setTitle("first answer", forState: UIControlState.Normal)
answer3.setTitle("first answer", forState: UIControlState.Normal)
answer4.setTitle("first answer", forState: UIControlState.Normal)
case 1:
QuestionText.text = "second question"
answer1.setTitle("second answer", forState: UIControlState.Normal)
answer2.setTitle("second answer", forState: UIControlState.Normal)
answer3.setTitle("second answer", forState: UIControlState.Normal)
answer4.setTitle("second answer", forState: UIControlState.Normal)
case 2:
QuestionText.text = "third question"
answer1.setTitle("third answer", forState: UIControlState.Normal)
answer2.setTitle("third answer", forState: UIControlState.Normal)
answer3.setTitle("third answer", forState: UIControlState.Normal)
answer4.setTitle("third answer", forState: UIControlState.Normal)
default:
break
}
println("youre on question \(questionNumber)")
questionNumber++
if questionNumber == 4 {
println("go to the next screen")
performSegueWithIdentifier("group1ToGroup2", sender: self)
}
}
func chooseQuestion2 (){
switch questionNumber{
case 0:
QuestionText.text = "forth question"
answer1.setTitle("4first answer", forState: UIControlState.Normal)
answer2.setTitle("4first answer", forState: UIControlState.Normal)
answer3.setTitle("4first answer", forState: UIControlState.Normal)
answer4.setTitle("4first answer", forState: UIControlState.Normal)
case 1:
QuestionText.text = "5-second question"
answer1.setTitle("5-second answer", forState: UIControlState.Normal)
answer2.setTitle("5-second answer", forState: UIControlState.Normal)
answer3.setTitle("5-second answer", forState: UIControlState.Normal)
answer4.setTitle("5-second answer", forState: UIControlState.Normal)
case 2:
QuestionText.text = "6-third question"
answer1.setTitle("6-third answer", forState: UIControlState.Normal)
answer2.setTitle("6-third answer", forState: UIControlState.Normal)
answer3.setTitle("6-third answer", forState: UIControlState.Normal)
answer4.setTitle("6-third answer", forState: UIControlState.Normal)
default:
break
}
println("youre on question \(questionNumber)")
questionNumber++
if questionNumber == 4 {
println("go to the next screen")
performSegueWithIdentifier("group1ToGroup2", sender: self)
}
}
func chooseQuestion3 (){
switch questionNumber{
case 0:
QuestionText.text = "7-first question"
answer1.setTitle("7-first answer", forState: UIControlState.Normal)
answer2.setTitle("7-first answer", forState: UIControlState.Normal)
answer3.setTitle("7-first answer", forState: UIControlState.Normal)
answer4.setTitle("7-first answer", forState: UIControlState.Normal)
case 1:
QuestionText.text = "8-second question"
answer1.setTitle("8-second answer", forState: UIControlState.Normal)
answer2.setTitle("8-second answer", forState: UIControlState.Normal)
answer3.setTitle("8-second answer", forState: UIControlState.Normal)
answer4.setTitle("8-second answer", forState: UIControlState.Normal)
case 2:
QuestionText.text = "9-third question"
answer1.setTitle("9-third answer", forState: UIControlState.Normal)
answer2.setTitle("9-third answer", forState: UIControlState.Normal)
answer3.setTitle("9-third answer", forState: UIControlState.Normal)
answer4.setTitle("9-third answer", forState: UIControlState.Normal)
default:
break
}
println("youre on question \(questionNumber)")
questionNumber++
if questionNumber == 4 {
println("go to the next screen")
performSegueWithIdentifier("group1ToGroup2", sender: self)
}
}
func chooseQuestion4 (){
switch questionNumber{
case 0:
QuestionText.text = "10-first question"
answer1.setTitle("10-first answer", forState: UIControlState.Normal)
answer2.setTitle("10-first answer", forState: UIControlState.Normal)
answer3.setTitle("10-first answer", forState: UIControlState.Normal)
answer4.setTitle("10-first answer", forState: UIControlState.Normal)
case 1:
QuestionText.text = "11-second question"
answer1.setTitle("11-second answer", forState: UIControlState.Normal)
answer2.setTitle("11-second answer", forState: UIControlState.Normal)
answer3.setTitle("11-second answer", forState: UIControlState.Normal)
answer4.setTitle("11-second answer", forState: UIControlState.Normal)
case 2:
QuestionText.text = "12-third question"
answer1.setTitle("12-third answer", forState: UIControlState.Normal)
answer2.setTitle("12-third answer", forState: UIControlState.Normal)
answer3.setTitle("12-third answer", forState: UIControlState.Normal)
answer4.setTitle("12-third answer", forState: UIControlState.Normal)
default:
break
}
println("youre on question \(questionNumber)")
questionNumber++
if questionNumber == 4 {
println("go to the next screen")
performSegueWithIdentifier("group1ToGroup2", sender: self)
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "group1ToGroup2" {
if let destinationVC = segue.destinationViewController as? TwoMultichoiceViewController {
destinationVC.zonePicked = zonePicked
destinationVC.group1 = group1
destinationVC.group2 = group2
}
}
}
}
TwoMultichoiceViewController.swift
//
// TwoMultichoiceViewController.swift
// MC_APP2
//
// Created by UDI-ME-TA on 08/05/2015.
// Copyright (c) 2015 UDI-ME-TA. All rights reserved.
//
import UIKit
class TwoMultichoiceViewController: UIViewController {
var zonePicked : String?
@IBOutlet var QuestionText: UILabel!
@IBOutlet var answer1: UIButton!
@IBOutlet var answer2: UIButton!
@IBOutlet var answer3: UIButton!
@IBOutlet var answer4: UIButton!
@IBOutlet var result: UILabel!
@IBOutlet var nextButton: UIButton!
var questionNumber = 0
var group1: [Int]!
var group2: [Int]!
override func viewDidLoad() {
super.viewDidLoad()
nextButton.hidden = true
if zonePicked == "zoneOne"{
self.chooseQuestion1()
}
else if zonePicked == "zoneTwo"{
self.chooseQuestion2()
}
else if zonePicked == "zoneThree"{
self.chooseQuestion3()
}
else {
self.chooseQuestion4()
}
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func answer1pressed(sender: AnyObject) {
nextButton.hidden = false
if questionNumber == 0 {
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}else if questionNumber == 1{
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}else if questionNumber == 2 {
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}
}
@IBAction func answer2pressed(sender: AnyObject) {
nextButton.hidden = false
if questionNumber == 0 {
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}else if questionNumber == 1{
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}else if questionNumber == 2 {
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}
}
@IBAction func answer3pressed(sender: AnyObject) {
nextButton.hidden = false
if questionNumber == 0 {
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}else if questionNumber == 1{
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}else if questionNumber == 2 {
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}
}
@IBAction func answer4pressed(sender: AnyObject) {
nextButton.hidden = false
if questionNumber == 0 {
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}else if questionNumber == 1{
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}else if questionNumber == 2 {
group2.append(1)
result.text="the points are \(group2.reduce(0,+))"
}
}
@IBAction func nextquestion(sender: AnyObject) {
if zonePicked == "zoneOne"{
self.chooseQuestion1()
}
else if zonePicked == "zoneTwo"{
self.chooseQuestion2()
}
else if zonePicked == "zoneThree"{
self.chooseQuestion3()
}
else {
self.chooseQuestion4()
}
nextButton.hidden = true
}
func chooseQuestion1 (){
switch questionNumber{
case 0:
QuestionText.text = "first question"
answer1.setTitle("first answer", forState: UIControlState.Normal)
answer2.setTitle("first answer", forState: UIControlState.Normal)
answer3.setTitle("first answer", forState: UIControlState.Normal)
answer4.setTitle("first answer", forState: UIControlState.Normal)
case 1:
QuestionText.text = "second question"
answer1.setTitle("second answer", forState: UIControlState.Normal)
answer2.setTitle("second answer", forState: UIControlState.Normal)
answer3.setTitle("second answer", forState: UIControlState.Normal)
answer4.setTitle("second answer", forState: UIControlState.Normal)
case 2:
QuestionText.text = "third question"
answer1.setTitle("third answer", forState: UIControlState.Normal)
answer2.setTitle("third answer", forState: UIControlState.Normal)
answer3.setTitle("third answer", forState: UIControlState.Normal)
answer4.setTitle("third answer", forState: UIControlState.Normal)
default:
break
}
println("youre on question \(questionNumber)")
questionNumber++
if questionNumber == 4 {
println("go to the next screen")
performSegueWithIdentifier("FinishMultiChoice", sender: self)
}
}
func chooseQuestion2 (){
switch questionNumber{
case 0:
QuestionText.text = "forth question"
answer1.setTitle("4first answer", forState: UIControlState.Normal)
answer2.setTitle("4first answer", forState: UIControlState.Normal)
answer3.setTitle("4first answer", forState: UIControlState.Normal)
answer4.setTitle("4first answer", forState: UIControlState.Normal)
case 1:
QuestionText.text = "5-second question"
answer1.setTitle("5-second answer", forState: UIControlState.Normal)
answer2.setTitle("5-second answer", forState: UIControlState.Normal)
answer3.setTitle("5-second answer", forState: UIControlState.Normal)
answer4.setTitle("5-second answer", forState: UIControlState.Normal)
case 2:
QuestionText.text = "6-third question"
answer1.setTitle("6-third answer", forState: UIControlState.Normal)
answer2.setTitle("6-third answer", forState: UIControlState.Normal)
answer3.setTitle("6-third answer", forState: UIControlState.Normal)
answer4.setTitle("6-third answer", forState: UIControlState.Normal)
default:
break
}
println("youre on question \(questionNumber)")
questionNumber++
if questionNumber == 4 {
println("go to the next screen")
performSegueWithIdentifier("FinishMultiChoice", sender: self)
}
}
func chooseQuestion3 (){
switch questionNumber{
case 0:
QuestionText.text = "7-first question"
answer1.setTitle("7-first answer", forState: UIControlState.Normal)
answer2.setTitle("7-first answer", forState: UIControlState.Normal)
answer3.setTitle("7-first answer", forState: UIControlState.Normal)
answer4.setTitle("7-first answer", forState: UIControlState.Normal)
case 1:
QuestionText.text = "8-second question"
answer1.setTitle("8-second answer", forState: UIControlState.Normal)
answer2.setTitle("8-second answer", forState: UIControlState.Normal)
answer3.setTitle("8-second answer", forState: UIControlState.Normal)
answer4.setTitle("8-second answer", forState: UIControlState.Normal)
case 2:
QuestionText.text = "9-third question"
answer1.setTitle("9-third answer", forState: UIControlState.Normal)
answer2.setTitle("9-third answer", forState: UIControlState.Normal)
answer3.setTitle("9-third answer", forState: UIControlState.Normal)
answer4.setTitle("9-third answer", forState: UIControlState.Normal)
default:
break
}
println("youre on question \(questionNumber)")
questionNumber++
if questionNumber == 4 {
println("go to the next screen")
performSegueWithIdentifier("FinishMultiChoice", sender: self)
}
}
func chooseQuestion4 (){
switch questionNumber{
case 0:
QuestionText.text = "10-first question"
answer1.setTitle("10-first answer", forState: UIControlState.Normal)
answer2.setTitle("10-first answer", forState: UIControlState.Normal)
answer3.setTitle("10-first answer", forState: UIControlState.Normal)
answer4.setTitle("10-first answer", forState: UIControlState.Normal)
case 1:
QuestionText.text = "11-second question"
answer1.setTitle("11-second answer", forState: UIControlState.Normal)
answer2.setTitle("11-second answer", forState: UIControlState.Normal)
answer3.setTitle("11-second answer", forState: UIControlState.Normal)
answer4.setTitle("11-second answer", forState: UIControlState.Normal)
case 2:
QuestionText.text = "12-third question"
answer1.setTitle("12-third answer", forState: UIControlState.Normal)
answer2.setTitle("12-third answer", forState: UIControlState.Normal)
answer3.setTitle("12-third answer", forState: UIControlState.Normal)
answer4.setTitle("12-third answer", forState: UIControlState.Normal)
default:
break
}
println("youre on question \(questionNumber)")
questionNumber++
if questionNumber == 4 {
println("go to the next screen")
performSegueWithIdentifier("FinishMultiChoice", sender: self)
}
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "FinishMultiChoice" {
if let destinationVC = segue.destinationViewController as? FinishMultichoiceViewController {
destinationVC.zonePicked = zonePicked
destinationVC.group1 = group1
destinationVC.group2 = group2
}
}
}
}
FinishMultichoiceViewController.swift
<pre>//
// FinishMultichoiceViewController.swift
// MC_APP2
//
// Created by UDI-ME-TA on 08/05/2015.
// Copyright (c) 2015 UDI-ME-TA. All rights reserved.
//
import UIKit
class FinishMultichoiceViewController: UIViewController {
var zonePicked : String?
var group1 = [Int]()
var group2 = [Int]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if let destinationVC = segue.destinationViewController as? ZonesViewController {
destinationVC.group1 = group1
destinationVC.group2 = group2
}
if let destinationVC = segue.destinationViewController as? ResultViewController {
destinationVC.group1 = group1
destinationVC.group2 = group2
}
performSegueWithIdentifier(zonePicked, sender: self)
}
override func performSegueWithIdentifier(identifier: String?, sender: AnyObject?) {
}
}
ResultViewController.swift
//
// ResultViewController.swift
// MC_APP2
//
// Created by UDI-ME-TA on 08/05/2015.
// Copyright (c) 2015 UDI-ME-TA. All rights reserved.
//
import UIKit
class ResultViewController: UIViewController {
var zonePicked : String?
var group1: [Int]!
var group2: [Int]!
@IBOutlet var ResultLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
var G1 = group1.reduce(0,+)
var G2 = group2.reduce(0,+)
if G1 >= G2 {
ResultLabel.text = "GROUP 1 IS THE WINNER"
} else {
ResultLabel.text = "GROUP 2 IS THE WINNER"
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
/*
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
}
*/
}