为什么xcode 7.1.1上的ResearchKit只允许我询问每种问题类型中的一种



所以我正试图用Swift在7.1.1上为ResearchKit编写一个代码,但我在问多个问题类型时遇到了问题。我所说的问题类型是指要求用户输入"文本字段"数据和"从列表中选择一个"数据
如果我只运行问题1和问题2的代码,它就会起作用。但如果我包括问题3,代码就会崩溃并给出错误。

import Foundation
import ResearchKit
public var SurveyTask: ORKOrderedTask {
var steps = [ORKStep]()
//TODO: add instructions step
let instructionStep = ORKInstructionStep(identifier: "IntroStep")
instructionStep.title = "Introduction"
instructionStep.text = "10 Questions that you can just answer or skip! (Althought we do hope you will answer them.)"
steps += [instructionStep]
//TODO: add questions
//question 1
let nameAnswerFormat = ORKTextAnswerFormat(maximumLength: 2)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle = "What is the child's age?"
let nameQuestionStep = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle, answer: nameAnswerFormat)
steps += [nameQuestionStep]
//question 2
let questQuestionStepTitle = "Has there been any other incidences of this disease in other family members?"
let textChoices = [
    ORKTextChoice(text: "Yes", value: 0),
    ORKTextChoice(text: "No", value: 1),
]
let questAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormatWithStyle(.SingleChoice, textChoices: textChoices)
let questQuestionStep = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle, answer: questAnswerFormat)
steps += [questQuestionStep]
  //question 3
let questQuestionStepTitle2 = "Is the tumor in one or both eyes?"
let textChoices2 = [
    ORKTextChoice(text: "Right Eye", value: 0),
    ORKTextChoice(text: "Left Eye", value: 1),
    ORKTextChoice(text: "Both Eyes", value: 2),
]
let questAnswerFormat2: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormatWithStyle(.SingleChoice, textChoices: textChoices2)
let questQuestionStep2 = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle2, answer: questAnswerFormat2)
steps += [questQuestionStep2]
/*//question 4
let questQuestionStepTitle3 = "Do you know anything about genetic counselling?"
let textChoices3 = [
    ORKTextChoice(text: "Yes", value: 0),
    ORKTextChoice(text: "No", value: 1),
]
let questAnswerFormat3: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormatWithStyle(.SingleChoice, textChoices: textChoices3)
let questQuestionStep3 = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle3, answer: questAnswerFormat3)
steps += [questQuestionStep3]
//question 5
let nameAnswerFormat2 = ORKTextAnswerFormat(maximumLength: 300)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle2 = "How did you first realize your child was sick?"
let nameQuestionStep2 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle2, answer: nameAnswerFormat2)
steps += [nameQuestionStep2]
//question 6
let nameAnswerFormat3 = ORKTextAnswerFormat(maximumLength: 300)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle3 = "What treatment is the child taking?"
let nameQuestionStep3 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle3, answer: nameAnswerFormat3)
steps += [nameQuestionStep3]
//question 7
let nameAnswerFormat4 = ORKTextAnswerFormat(maximumLength: 100)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle4 = "How long has the treatment been ongoing?"
let nameQuestionStep4 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle4, answer: nameAnswerFormat4)
steps += [nameQuestionStep4]
//question 8
let nameAnswerFormat5 = ORKTextAnswerFormat(maximumLength: 300)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle5 = "What major questions do you have about the process and about the treatment itself?"
let nameQuestionStep5 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle5, answer: nameAnswerFormat5)
steps += [nameQuestionStep5]
//question 9
let nameAnswerFormat6 = ORKTextAnswerFormat(maximumLength: 300)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle6 = "Are there any side effects of the treatment?? State any if there is."
let nameQuestionStep6 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle6, answer: nameAnswerFormat6)
steps += [nameQuestionStep6]
//question 10
let nameAnswerFormat7 = ORKTextAnswerFormat(maximumLength: 100)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle7 = "How has your day been? "
let nameQuestionStep7 = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle7, answer: nameAnswerFormat7)
steps += [nameQuestionStep7]*/


//TODO: add summary step
let summaryStep = ORKCompletionStep(identifier: "SummaryStep")
summaryStep.title = "Right. Off you go!"
summaryStep.text = "That was easy!"
steps += [summaryStep]
return ORKOrderedTask(identifier: "SurveyTask", steps: steps)
}

任何帮助都将不胜感激,谢谢!

问题3:
尝试将标识符更改为#2:

let questQuestionStep2 = ORKQuestionStep(identifier: "TextChoiceQuestionStep2",...

相关内容

  • 没有找到相关文章

最新更新