[英]How to close ResearchKit Modal view in SwiftUI?
I am using SwiftUI to program a research kit app for personal use and I was wondering how to interact with Modal View opened Research Kit survey task.我正在使用 SwiftUI 编写一个供个人使用的研究套件应用程序,我想知道如何与打开的模态视图研究套件调查任务进行交互。
I am using this code at the moment to open the view:我目前正在使用此代码打开视图:
struct SurveyView: UIViewControllerRepresentable {
typealias UIViewControllerType = ORKTaskViewController
func makeUIViewController(context: Context) -> ORKTaskViewController {
let taskViewController = ORKTaskViewController(task: SurveyTask, taskRun: nil)
taskViewController.view.tintColor = UIColor(red:0.64, green:0.15, blue:0.11, alpha:1.00)
return taskViewController
}
func updateUIViewController(_ taskViewController: ORKTaskViewController, context: Context) {
}
}
I am using a button to call it, however I can't make it close with the cancel or done button in research kit as I am in the dark as to where I should implement the didFinishWithReason reason: ORKTaskViewControllerFinishReason
.我正在使用一个按钮来调用它,但是我无法使用研究工具包中的取消或完成按钮关闭它,因为我不知道应该在哪里实现didFinishWithReason reason: ORKTaskViewControllerFinishReason
。
Any help would be very much appreciated.任何帮助将不胜感激。
I have managed to do it using Coordinators.我已经设法使用协调器来做到这一点。 If anyone is interested, here is the code.如果有人感兴趣,这里是代码。
struct SurveyView: UIViewControllerRepresentable {
func makeCoordinator() -> Coordinator {
Coordinator()
}
typealias UIViewControllerType = ORKTaskViewController
func makeUIViewController(context: Context) -> ORKTaskViewController {
let taskViewController = ORKTaskViewController(task: SurveyTask, taskRun: nil)
taskViewController.view.tintColor = UIColor(red:0.64, green:0.15, blue:0.11, alpha:1.00)
taskViewController.delegate = context.coordinator
return taskViewController
}
func updateUIViewController(_ taskViewController: ORKTaskViewController, context: Context) {
}
class Coordinator: NSObject, ORKTaskViewControllerDelegate {
func taskViewController(_ taskViewController: ORKTaskViewController, didFinishWith reason: ORKTaskViewControllerFinishReason, error: Error?) {
taskViewController.dismiss(animated: true, completion: nil)
}
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.