0

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
4

1 に答える 1

1

resultSelector( docs )の機能は、述語が一致する正確な結果を識別することです。AresultSelectorには が必要ですresultIdentifier。これは、質問の手順では、質問の手順の識別子とその中の質問の結果の両方です (ジャンプ先の手順の識別子ではありません!)。

必要に応じresultSelectorて、 a stepIdentifier(フォームの結果を一致させたい場合、同じステップに複数のユーザーを含めることができます) またはtaskIdentifier(以前に完了したタスクの結果を一致させたい場合) を持つことができます。ユースケースにはこれら2つは必要ないと思います。

resultSelector次に、関心のある質問への有効なポイントを使用して、結果の述語を作成し、その述語を使用して を作成しますORKPredicateStepNavigationRule(destinationStepIdentifierこれがジャンプ先のステップです)。

最後に、述語ステップ ナビゲーション ルールを、ルールをトリガーする必要があるステップ (述語によって一致する同じステップ、またはタスクの後半に表示されるステップ) にアタッチします。

すべてを設定してタスクを実行すると、関連付けられているステップを離れるときにナビゲーション ルールがトリガーされ、ナビゲーション ルールに含まれるdestinationIdentifierは、条件付きでジャンプするステップを指します。

Swiftで条件付きジャンプを実現する方法の完全な例については、TaskFactory.swiftファイル (サンプル プロジェクトでNavigable Ordered Taskアイテムを実装する) を参照してください。ORKTest

ORKNavigableOrderedTask詳細については、ORKPredicateStepNavigationRuleおよびのドキュメントも確認してORKResultPredicateください。

これらを使用することで、あなたが望むものを達成できると思います。


さらに、スキップ ナビゲーション ルールの概念を に追加する進行中のプル リクエストがあります。これは、ニーズにより具体的に適している可能性があります。ただし、最初に一般的なナビゲーション ルールがどのように機能するかを理解することをお勧めします。そのPRがすぐに統合されることを願っています。ORKNavigableTask

于 2016-03-17T18:21:09.190 に答える