[英]Apple Research kit example Asthma app doesn't run properly
[英]Can't skip a step using research kit
目前,我正在使用研究工具包構建應用程序。 以下是我的問題。
let onsetQuestionStepTitle = "Title"
let onsetQuestionStepQuestion = "Question Name"
let onsetTextChoices = [
ORKTextChoice(text: "superb", value: 0 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "great", value: 1 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "fair", value: 2 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "not good", value: 3 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "bad", value: 4 as NSCoding & NSCopying & NSObjectProtocol)
]
let onsetAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: onsetTextChoices)
let onsetQuestionStep = ORKQuestionStep(identifier: "twoAwakeSurvey", title: onsetQuestionStepTitle, question: onsetQuestionStepQuestion, answer: onsetAnswerFormat)
steps += [onsetQuestionStep]
如果用戶點擊“ superb”,我想跳到帶有標識符“ threeAwakeSurvey”的下一步,然后轉到“ fourAwakeSurvey”。 為此,我實現了以下代碼。
var task = ORKNavigableOrderedTask(identifier: "StepNavigationTaskIdentifier", steps: steps)
let resultSelector: ORKResultSelector = ORKResultSelector(resultIdentifier: "twoAwakeSurvey")
let askLocation = ORKResultPredicate.predicateForChoiceQuestionResult(with: resultSelector, expectedAnswerValue: 0 as NSCoding & NSCopying & NSObjectProtocol)
let locationNavigationRule = ORKPredicateSkipStepNavigationRule(resultPredicate: askLocation)
task.setSkip(locationNavigationRule, forStepIdentifier: "threeAwakeSurvey")
但是,這不起作用。 我閱讀了文檔,但仍然不明白為什么。
我在操場上及其工作中嘗試了以下代碼。 也許您的第3步標識符不正確。
let onsetQuestionStepTitle = "Title"
let onsetQuestionStepQuestion = "Question Name"
let onsetTextChoices = [
ORKTextChoice(text: "superb", value: 0 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "great", value: 1 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "fair", value: 2 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "not good", value: 3 as NSCoding & NSCopying & NSObjectProtocol),
ORKTextChoice(text: "bad", value: 4 as NSCoding & NSCopying & NSObjectProtocol)
]
let onsetAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: onsetTextChoices)
let onsetQuestionStep = ORKQuestionStep(identifier: "twoAwakeSurvey", title: onsetQuestionStepTitle, question: onsetQuestionStepQuestion, answer: onsetAnswerFormat)
let threeAwakeSurveyStep = ORKInstructionStep(identifier: "threeAwakeSurvey")
threeAwakeSurveyStep.title = "Three"
let fourAwakeSurveyStep = ORKInstructionStep(identifier: "fourAwakeSurvey")
fourAwakeSurveyStep.title = "Four"
let steps = [onsetQuestionStep, threeAwakeSurveyStep, fourAwakeSurveyStep]
var task = ORKNavigableOrderedTask(identifier: "StepNavigationTaskIdentifier", steps: steps)
let resultSelector: ORKResultSelector = ORKResultSelector(resultIdentifier: "twoAwakeSurvey")
let askLocation = ORKResultPredicate.predicateForChoiceQuestionResult(with: resultSelector, expectedAnswerValue: 0 as NSCoding & NSCopying & NSObjectProtocol)
let locationNavigationRule = ORKPredicateSkipStepNavigationRule(resultPredicate: askLocation)
task.setSkip(locationNavigationRule, forStepIdentifier: "threeAwakeSurvey")
let taskVC = ORKTaskViewController(task: task, taskRun: nil)
PlaygroundPage.current.liveView = taskVC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.