ResearchKit を使用して小さなアプリに取り組んでいます。残念ながら、前の質問の回答に基づいて質問をスキップする方法を理解するのに十分な例を見つけることができませんでした. 以下のコードをまとめましたが、これは問題がなく、機能していません。よくないことを理解するための助けを探しています。
let textChoices2 = [
ORKTextChoice(text: "Answer 1", value: 0),
ORKTextChoice(text: "Answer 2", value: 1),
ORKTextChoice(text: "Answer 3", value: 2),
ORKTextChoice(text: "Answer 4", value: 3)
]
let questAnswerFormat2: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormatWithStyle(.SingleChoice, textChoices: textChoices2)
let questQuestionStep2 = ORKQuestionStep(identifier: "TextChoiceQuestionStep2", title: questQuestionStepTitle, answer: questAnswerFormat2)
//////////////////////////// Here I need help
let task: ORKNavigableOrderedTask = ORKNavigableOrderedTask(identifier: "xyz123", steps: steps)
//the identifier for ORKNavigableOrderedTask is a random number in my case, is it ok like this?
let resultSelector: ORKResultSelector = ORKResultSelector(stepIdentifier: "TextChoiceQuestionStep", resultIdentifier: "ImageChoiceQuestionStep”)
//stepIdentifier is the question based on which I decide if I want to skip the current question. Is it ok like this?
//resultIdentifier is the question to which I want to jump to. Is it ok like this?
let predicate: NSPredicate = ORKResultPredicate.predicateForChoiceQuestionResultWithResultSelector(resultSelector, expectedAnswerValue: "0”)
//expectedAnswerValue is the value of the answer for which I want to skip the current question. Is it ok like this?
let predicateRule: ORKPredicateStepNavigationRule = ORKPredicateStepNavigationRule(resultPredicatesAndDestinationStepIdentifiers:[ (predicate, "ImageChoiceQuestionStep") ])
//“ImageChoiceQuestionStep” from the row above is the question to which I want to jump to. Is it ok like this?
task.setNavigationRule(predicateRule, forTriggerStepIdentifier: "ImageChoiceQuestionStep”)
//“ImageChoiceQuestionStep” from the row above is the question to which I want to jump to. Is it ok like this?
questQuestionStep2.task = task