Search code examples
iosswiftsegue

Swift 4 Call ViewWillAppear after dismissing View Controller


I would like to call viewWillAppear after dismissing a layover ViewController.

ViewController1 -> Segue -> ViewController2

In VeiwController2

1.)

self.dismiss(animated: true, completion: nil)

2.)

 override func viewDidDisappear(_ animated: Bool) {

       ViewController1().viewWillAppear(true)

    }

In VeiwController1

When viewWillAppear is called im getting null errors crashing my app. How can i dismiss a overContext ViewController and call the viewWillAppear method in a correct manner.


Solution

  • viewWillAppear is called automatically when you dismiss VC2. Delete: ViewController1().viewWillAppear(true)

    Try deleting:

    super.viewWillAppear(animated) in VC1. viewDidAppear not getting called

    Does it even go back to your VC? self.dismiss works with "Present Modally" segue here. Or embed in NavigationBar, with popViewController