I created 2 views, one is using a protocol and a delegate. For the first view, the Delegate function is not called.
My FirstView Controller: here I access the delegate function.
import UIKit
class NextViewController: UIViewController,DurationSelectDelegate {
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()
}
}
My SecondView Controller: Here I create a delegate.
import UIKit
protocol DurationSelectDelegate {
func DurationSelected()
}
class DurationDel: UIViewController {
var delegate: DurationSelectDelegate?
@IBAction func Previous(sender : AnyObject) {
delegate?.DurationSelected()
self.navigationController.popViewControllerAnimated(true)
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
source
share