gpt4 book ai didi

ios - 在 ViewController 中实现 ResearchKit 以进行调查

转载 作者:行者123 更新时间:2023-11-29 01:12:22 27 4
gpt4 key购买 nike

编辑:不确定这是否是我的问题的根源,但应用委托(delegate)中的这段代码是否会成为它不起作用的原因?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let navigationController = self.window!.rootViewController as! UINavigationController
let controller = navigationController.topViewController as! HomeViewController
controller.managedObjectContext = self.managedObjectContext
return true

}

我正在尝试将调查功能添加到集成了 ResearchKit 的应用程序中。我已经阅读了 Ray Wenderlich 的设置指南和其他一些教程。然而,当我过渡到一个我想开发的应用程序时,我有点卡住了。

我被抛出一个错误: 无法将类型“HomeviewController 的值分配给类型“ORKTaskViewControllerDelegate?”?

这是我正在使用的代码:

class HomeViewController: UIViewController {
var managedObjectContext: NSManagedObjectContext?

@IBAction func surveyTapped(sender: AnyObject) {

let taskViewController = ORKTaskViewController(task: SurveyTask, taskRunUUID: nil)
taskViewController.delegate = self
presentViewController(taskViewController, animated: true, completion: nil)

}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.destinationViewController.isKindOfClass(NewRideViewController) {
if let newRideViewController = segue.destinationViewController as? NewRideViewController {
newRideViewController.managedObjectContext = managedObjectContext
}
}
}
}

基于与此错误语法类似的问题,用户添加了另一个 Controller 类,但我不知道是哪个。非常感谢您的帮助,谢谢 StackExchange!

最佳答案

看起来您还没有扩展 View Controller 来实现 ORKTaskViewController 的委托(delegate),即 ORKTaskViewControllerDelegate 并且您的 VC 代码应如下 -

import ResearchKit

class HomeVC: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}

@IBAction func surveyTapped(sender: AnyObject) {
let taskViewController = ORKTaskViewController(task: SurveyTask, taskRunUUID: nil)
taskViewController.delegate = self
presentViewController(taskViewController, animated: true, completion: nil)
}

}

extension HomeVC: ORKTaskViewControllerDelegate {

func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) {

}

}

关于ios - 在 ViewController 中实现 ResearchKit 以进行调查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35591974/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com