[英]Can't connect custom IBAction to button
我正在快速浏览ResearchKit教程( http://www.raywenderlich.com/104575/researchkit-tutorial-with-swift ),但无法将我的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)
}
}
我进入主故事板,然后单击“视图控制器”,然后尝试将我的类都设置为“ ViewController”和“ UIViewController”,方法应该显示在“已发送事件”中,但事实并非如此。 我也尝试了ctrl拖动,但这对我也不起作用。
问题是,在将视图控制器类设置为IBaction方法所在的类时,我没有将ctrl从我的按钮直接拖动到黄色视图控制器按钮。
您可以@IBAction
将@IBAction
的参数从(_ sender: Any)
更改为(_ sender: AnyObject)
。 并请尝试使用Ctrl + Drag。
它可能会起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.