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

问题描述 投票:0回答:1

所以我试图用DSift在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)
}

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

xcode swift researchkit
1个回答
0
投票

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

let questQuestionStep2 = ORKQuestionStep(identifier: "TextChoiceQuestionStep2",...
© www.soinside.com 2019 - 2024. All rights reserved.