0
我對其他問題類型成功使用了ResearchKit的stepResultForStepIdentifier
方法,但無法找到正確的語法來預先填充TextChoiceQuestion的結果。ResearchKit對於TextChoiceQuestion的stepResult
以下是在ORKCatalog中爲示例TextChoice問題設置結果的不成功嘗試。任何正確的方法建議?
func stepResultForStepIdentifier(stepIdentifier: String) -> ORKStepResult? {
var stepResults = [ORKQuestionResult]()
if stepIdentifier == "TextChoiceQuestionStep" {
var questionDefault = ORKChoiceQuestionResult(identifier: stepIdentifier)
questionDefault.choiceAnswers?.append("choice_2")
stepResults.append(questionDefault)
}
var defaults = ORKStepResult(stepIdentifier: stepIdentifier, results: stepResults)
return defaults
}
謝謝。這樣可行。我添加了一個用於檢查所述陣列是否是nil - '如果questionDefault.choiceAnswers ==零{ questionDefault.choiceAnswers = [ 「choice_2」] }否則{ questionDefault.choiceAnswers .append( 「choice_2」) ?}' – Brendenw