【发布时间】:2016-02-16 22:28:56
【问题描述】:
我正在学习 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 拖动,但也没有用。
【问题讨论】:
-
我认为你需要一个强引用来持有 taskViewController 来呈现。
标签: ios xcode swift ibaction researchkit