3

当用户在具有谓词导航规则的步骤中单击“跳过”按钮时,如何指定用户将被重定向到的步骤?

现在它重定向到任务的开始。

这是可选步骤:

// multiple choices question
let multipleQuestionsStepTitle = "what is your gender ?"
let textChoices = [ORKTextChoice(text: "Female", value: 0),
                   ORKTextChoice(text: "Male", value: 1),
                   ORKTextChoice(text: "idk", value: 2)]
let multipleQuestionsAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormatWithStyle(.SingleChoice, textChoices: textChoices)
let multipleQuestionsStep = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: multipleQuestionsStepTitle, answer: multipleQuestionsAnswerFormat)
multipleQuestionsStep.optional = true

steps += [multipleQuestionsStep]

这是导航规则:

let task = ORKNavigableOrderedTask(identifier: "SurveyTask", steps: steps)

var predicateRule: ORKPredicateStepNavigationRule
let predicateFemale: NSPredicate = ORKResultPredicate.predicateForChoiceQuestionResultWithResultSelector(ORKResultSelector(resultIdentifier: "TextChoiceQuestionStep"), expectedAnswerValue: 0)
// invert of previous predicate
let predicateNotFemale: NSPredicate = NSCompoundPredicate.init(notPredicateWithSubpredicate: predicateFemale)
predicateRule = ORKPredicateStepNavigationRule.init(resultPredicates: [predicateNotFemale], destinationStepIdentifiers: ["IntroStep"], defaultStepIdentifier: "ImageChoiceQuestionStep", validateArrays: false)

task.setNavigationRule(predicateRule, forTriggerStepIdentifier: "TextChoiceQuestionStep")

我假设如果我们跳过这一步,我们将被重定向到defaultStepIdentifier,但这里不是这种情况。

如果我们有导航规则,我在文档中没有找到任何关于将 optional 设置为 false 的内容,所以也许有人有关于如何做到这一点的解决方案?

4

0 回答 0