IOS segue问题

时间:2016-03-10 16:11:37

标签: ios iphone swift segue unwind-segue

我已经构建了一个带有测验部分的应用。测验在每个部分后有4个部分,它会展开测试主屏幕以存储结果,然后转到下一部分。在最后一节之后,它返回到测试主页并将所有收集的所有部分的分数发送到结果屏幕。这就是问题开始的地方showResultsScreen segue可以传递结果并显示它们,但是当测试主页再次接管时,屏幕上只剩下不到一秒的时间。结果调用segue的resultsScreenViewController中没有代码。我唯一能想到的就是第4节 - > quizHome是一个unwindSegue,来自quizHome - >结果是定期显示segue。他们的行为有何不同?

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 - >结果

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

resultsScreenViewcontroller中只有几行代码来设置带有分数的文本标签

0 个答案:

没有答案