首页 > 解决方案 > 如何在一系列问题中后退或前进?

问题描述

我有一系列问题是字典中的关键。每个问题对应的选择是每个键的值。如果用户决定要跳过一个问题或返回一个问题,我希望用户能够出于导航原因跳过或返回一个问题。这是我的快速代码:

       @IBAction func goNext(_ sender: Any) {
}

func nextQ(sender: UIButton) {
    if sender == nextButton {
        questionTitle.text = surveyQuestions[1]
    }
}



var surveyQuestions = [String]()

func startSurvey() {
    
    if surveyQuestions.isEmpty {
        surveyQuestions = Array(SampleSurvey().surveyquestions.keys)
        print(surveyQuestions)
    }
    
    let rand = Int(arc4random_uniform(UInt32(surveyQuestions.count)))
    questionTitle.text = surveyQuestions[rand]
    
    var choices = SampleSurvey().surveyquestions[surveyQuestions[rand]]!
    print(choices)
    print(choices.count)
    print(surveyChoices.count)
    surveyQuestions.remove(at: rand)

  }

IBAction 是“跳过”按钮。我希望它的功能如下:按下按钮并将数组中的下一个问题呈现给用户。我还希望用户能够返回并再次向他们展示上一个问题以及相应的值/选择。我怎样才能实现这个所需的功能?

这是我当前功能的屏幕截图,当我单击屏幕底部的后退或下一步时,没有任何反应。我希望通过单击下一步来呈现新问题,或者通过单击返回来呈现旧问题以及相应的选项

截屏

标签: iosswift

解决方案


推荐阅读