我收到错误 [类型 "View Controller" 不符合协议 "ORKTaskViewControllerDelegate"]



我刚刚开始在 Xcode 中使用 swift3 来利用 Apple.inc 提供的 ResearchKit。虽然我已经完成了 Researchkit Tutorial with Swift: Getting started in Ray Wenderlich 中的教程,但我在 ViewController 的扩展中遇到了麻烦。以下是我的代码。

import ResearchKit
import UIKit
class ViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
  }
  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
  @IBAction func consentTapped(sender : AnyObject) {
    let taskViewController = ORKTaskViewController(task: ConsentTask, taskRun: nil)
    taskViewController.delegate = self
    present(taskViewController, animated: true, completion: nil)
  }
}
extension ViewController: ORKTaskViewControllerDelegate {
  func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason
         reason: ORKTaskViewControllerFinishReason, error: NSError?) {
    //Handle results with taskViewController.result
    taskViewController.dismiss(animated:true, completion: nil)
  }
}

您错过了添加委托。将ORKTaskViewControllerDelegate添加到视图控制器

class ViewController: UIViewController,ORKTaskViewControllerDelegate {
   override func viewDidLoad() {
    super.viewDidLoad(
   }
}

相关内容

  • 没有找到相关文章

最新更新