简体   繁体   中英

Can't connect custom IBAction to button

I'm following a ResearchKit tutorial in swift ( http://www.raywenderlich.com/104575/researchkit-tutorial-with-swift ) and I can't connect either of my IBaction methods to buttons in the main storyboard. Here's the code (from the tutorial):

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)
      }

}

I go into the main storyboard and click on the View Controller, and I've tried setting my class both to ViewController and UIViewController, and the methods are supposed to show up in Sent Events, but they don't. I've also tried ctrl dragging, and that hasn't worked for me either.

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

You can change the @IBAction 's argument from (_ sender: Any) to (_ sender: AnyObject) , but manually. And try to use Ctrl+Drag, please.

It might work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM