【发布时间】:2019-10-21 04:09:29
【问题描述】:
我从 GitHub 下载了latest release of ResearchKit 并将框架嵌入到我的项目中。
使用Ray Wenderlich Tutorial on ResearchKit,我创建了一个调查任务:
import ResearchKit
public var SurveyTask: ORKOrderedTask {
var steps = [ORKStep]()
let instructionStep = ORKInstructionStep(identifier: "IntroStep")
instructionStep.title = "The Questions Three"
instructionStep.text = "Who would cross the Bridge of Death must answer me these questions three, ere the other side they see."
steps += [instructionStep]
let nameAnswerFormat = ORKTextAnswerFormat(maximumLength: 20)
nameAnswerFormat.multipleLines = false
let nameQuestionStepTitle = "What is your name?"
let nameQuestionStep = ORKQuestionStep(identifier: "QuestionStep", title: nameQuestionStepTitle, question: "Hello?", answer: nameAnswerFormat)
steps += [nameQuestionStep]
let questQuestionStepTitle = "What is your quest?"
let textChoices = [
ORKTextChoice(text: "Create a ResearchKit App", value: 0 as NSNumber),
ORKTextChoice(text: "Seek the Holy Grail", value: 1 as NSNumber),
ORKTextChoice(text: "Find a shrubbery", value: 2 as NSNumber)
]
let questAnswerFormat: ORKTextChoiceAnswerFormat = ORKAnswerFormat.choiceAnswerFormat(with: .singleChoice, textChoices: textChoices)
let questQuestionStep = ORKQuestionStep(identifier: "TextChoiceQuestionStep", title: questQuestionStepTitle, question: "Hello?", answer: questAnswerFormat)
steps += [questQuestionStep]
let summaryStep = ORKCompletionStep(identifier: "SummaryStep")
summaryStep.title = "Right. Off you go!"
summaryStep.text = "That was easy!"
steps += [summaryStep]
return ORKOrderedTask(identifier: "SurveyTask", steps: steps)
}
我的 ViewController 中的委托是这样设置的:
extension ViewController: ORKTaskViewControllerDelegate {
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
taskViewController.dismiss(animated: true, completion: nil)
}
}
然后在那个 ViewController 中,我尝试展示 ORKTaskViewController:
@objc func showSurvey() {
let taskViewController = ORKTaskViewController(task: SurveyTask, taskRun: nil)
taskViewController.delegate = self
self.present(taskViewController, animated: true, completion: nil)
}
我不断收到libc++abi.dylib: terminating with uncaught exception of type NSException,但我不太清楚为什么。我没有使用故事板,但我不明白为什么没有故事板就不能使用 ResearchKit。我试图搜索没有情节提要的实现,但我能找到的最接近的是this,它仍然使用情节提要。任何帮助将不胜感激。
【问题讨论】:
标签: ios swift interface-builder researchkit