对于其他问题类型,我正在成功地使用ResearchKit的stepResultForStepIdentifier方法,但无法找到正确的语法预先填充TextChoiceQuestion的结果。
下面是在TextChoice中设置示例ORKCatalog问题结果的失败尝试。对正确的方法有什么建议吗?
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
}发布于 2015-06-04 17:22:54
choiceAnswers数组是nil吗?当您执行questionDefault.choiceAnswers?.append时,choiceAnswers可能是nil,因此这可能没有任何作用。
相反,做questionDefault.choiceAnswers = ["choice_2"]
https://stackoverflow.com/questions/30649369
复制相似问题