Can't connect custom IBAction to button

581 views Asked by At

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.

2

There are 2 answers

0
Lin On

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.

1
lirael On

The issue was that I was not ctrl-dragging from my button directly to the yellow view controller button while the view controller class was set to the class where my IBaction methods were.