0

i have built an app with a quiz section. the quiz has 4 sections after each section it unwinds to the test home screen to store the results and then segue to the next section. after the last section it returns to the test home and sends all the gathered scores from all the sections to a results screen. thats where the the problem starts the showResultsScreen segue works passing the results and displaying them but the only stay on the screen for less than a second when the test home takes over again. there no no code in the resultsScreenViewController that is calling the segue. The only thing i can think is causing it is that section4 -> quizHome is an unwindSegue and the one from quizHome -> Results is a regular show segue. do they behave differently?

section4 -> quizHome

@IBAction func finishQuizAction(sender: AnyObject) {
    if(answerOne.selectedSegmentIndex == 1 ||
        answerTwo.selectedSegmentIndex == 1 ||
        answerThree.selectedSegmentIndex == 0){
            needsTest = true
    }else if(answerOne.selectedSegmentIndex == 0 ||
        answerTwo.selectedSegmentIndex == 0 ||
        answerThree.selectedSegmentIndex == 1){
            needsTest = false

    }
    performSegueWithIdentifier("exitSectionFour", sender: self)
}

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    // Get the new view controller using segue.destinationViewController.
    // Pass the selected object to the new view controller.
    let dest = segue.destinationViewController as! EyeTestViewController
    dest.isFinished = true
    dest.testNo++
}

quizhome -> Results

func displayResults(){
    isFinished = true
    print("this is where we should segue to results")
    performSegueWithIdentifier("goToResults", sender: nil)
}


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

    if(isFinished){
        print("test no. going to Results = \(testNo)------")
        let resultsScreen = segue.destinationViewController as! ResultsScreenViewController

        resultsScreen.secOnePartOne = "\(secOnePartOneScore) Out of 6"
        resultsScreen.secOnePartTwo = "\(secOnePartTwoScore) Out of 6"
        resultsScreen.secTwo = "\(secTwoScore) Out of 12"

        if(secThree[0] == true){
            resultsScreen.secThreeScore = "Pass"
        } else if(secThreeScore[0] == false){
            resultsScreen.secThreeScore = "Fail"
            needsTest = true
        }

        if(secThree[1] == true){
            resultsScreen.secThreeScore = "Pass"
        } else if(secThree[1] == false){
            resultsScreen.secThreeScore = "Fail"
            needsTest = true
        }

        var leftSecFour = 0
        var rightSecFour = 0
        for (var x = 0; x < secFour.count; x++ ){
            if(x == 0 || x == 1){
                if(secFour[x] == true){
                    leftSecFour++
                }
            }else if(x == 2 || x == 3){
                if(secFour[x] == true){
                    rightSecFour++
                }
            }


        }

        if((leftSecFour + rightSecFour) < 4){
            needsTest = true
        }

        resultsScreen.leftSecFour = "\(leftSecFourScore) Out of 2"
        resultsScreen.rightSec = "\(rightSecFourScore) Out of 2"

        // recomendation

        if(leftSecFourScore < 5 || rightSecFourScore < 5){
            needsTest = true
        }

        if(needsTest){
            resultsScreen.recomendationText = "Un Lucy Message"
        }else{
            resultsScreen.recomendationText = "Congratulations!"
        }

        isFinished = false
    }
}// end prepareForSegue

there is only a few lines of code in resultsScreenViewcontroller to set the text labels with the scores

Lonergan6275
  • 1,938
  • 6
  • 32
  • 63
  • So you unwind to the home screen and then immediately to the next section? Just to store some stuff? Regardless of your issue, that is definitely not the best way to send stuff to another screen. The home screen doesnt have to be visible on screen for you to send stuff to it. I would recommend using the proper ways of communicating between two view controllers. See http://stackoverflow.com/questions/5210535/passing-data-between-view-controllers (code is in objective c, but there are plenty of resources for each solution in swift) – Will M. Mar 10 '16 at 17:15
  • i was aware this is not the best way. but i don't have time to redesign the flow at the moment. but will defiantly come back to it. for the moment i just want to know why it is going back to the quiz when i cant find any code that is telling it to. – Lonergan6275 Mar 10 '16 at 17:19

0 Answers0