Wednesday 21 February 2018

Pass the Values using Delegate and Protocol - Swift

Pass the Values using Delegate and Protocol - Swift

protocol NewEventAddedDelegate {
    func new_event_chk(stats: Bool)
}
class SecondViewController: UIViewController {
var event_delegate: NewEventAddedDelegate?

@IBAction func back_action(_ sender: UIButton) {
        self.event_delegate?.new_event_chk(stats: false)
self.navigationController?.popViewController(animated: true)
}

@IBAction func back_with_value_action(_ sender: UIButton) {
        self.event_delegate?.new_event_chk(stats: true)
self.navigationController?.popViewController(animated: true)
}
}

class FirstViewController: UIViewController, NewEventAddedDelegate {

func new_event_chk(stats: Bool) {
        if stats == true
        {
            print("ADDED-NEW-EVENT")
            //present a form
            let when = DispatchTime.now() + 2
DispatchQueue.main.asyncAfter(deadline: when) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "NewVC") as! NewVC
self.present(vc, animated: true, completion: nil)
            }
        }
    }
}

No comments: