How can I specify a step where user will be redirect to when he clicks on ‘skip‘ button in a step with predicate navigation rules ?
For now it redirects to the start of the task.
Here is the optional step :
// 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]
And here is the navigation rule:
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")
I would assume that if we skip the step, we would be redirect to the defaultStepIdentifier
, but it's not the case here.
I didn't find anything in documentation about setting optional to false if we have navigation rules, so maybe someone has a solution on how to do that?