Delegate Not Called In SWIFT iOS
ios, swift
Solution
To me, it looks like you're pushing a view controller that you haven't actually set the delegate for. If you change your "Next" function, to include the line
nextViewController.delegate = self
You should see that the delegation works. In doing this, you can also probably remove the creation of "secondController", as it looks like that's redundant.
Problem
I am Created 2 Views, One is and Used Protocol and Delegate. For first view the Delegate function is not called. My FirstView Controller : Here I am Accessing the Delegate Function. ``` import UIKit class NextViewController: UIViewController,DurationSelectDelegate { //var secondController: DurationDel? var secondController: DurationDel = DurationDel() @IBAction func Next(sender : AnyObject) { let nextViewController = DurationDel(nibName: "DurationDel", bundle: nil) self.navigationController.pushViewController(nextViewController, animated: true) } override func viewDidLoad() { super.viewDidLoad() secondController.delegate=self } func DurationSelected() { println("SUCCESS") } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } ``` My SecondView Controller : Here I Am creating Delegate. ``` import UIKit protocol DurationSelectDelegate { func DurationSelected() } class DurationDel: UIViewController { var delegate: DurationSelectDelegate? @IBAction func Previous(sender : AnyObject) { //let game = DurationSelectDelegate() delegate?.DurationSelected() self.navigationController.popViewControllerAnimated(true) } override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } ```