0

我正在关注 swift ( http://www.raywenderlich.com/104575/researchkit-tutorial-with-swift ) 中的 ResearchKit 教程,但我无法将任何一种 IBaction 方法连接到主情节提要中的按钮。这是代码(来自教程):

import ResearchKit

 class ViewController: UIViewController {

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

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

extension ViewController : ORKTaskViewControllerDelegate {

    func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) {
        taskViewController.dismissViewControllerAnimated(true, completion: nil)
      }

}

我进入主情节提要并单击 View Controller,我尝试将我的类设置为 ViewController 和 UIViewController,并且这些方法应该显示在 Sent Events 中,但它们没有。我也尝试过 ctrl 拖动,但这对我也不起作用。

4

2 回答 2

1

问题是当视图控制器类设置为我的 IBaction 方法所在的类时,我没有从我的按钮直接拖动到黄色视图控制器按钮。

于 2016-02-17T00:40:55.307 回答
1

您可以手动将@IBAction' 参数从(_ sender: Any)更改为 。(_ sender: AnyObject)请尝试使用 Ctrl+Drag。

它可能会起作用。

于 2017-01-03T04:36:13.330 回答