简体   繁体   中英

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.

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

// Override this function in ViewController1
override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(true)

 //Your code here will execute after viewDidLoad() or when you dismiss the child viewController  

}

I'd suggest you go through the life cycle of ViewController. Apple documentation for ViewController life cycle

yout modal should be .fullScreen

Try with this:

let createAccounts = CreateAccounts();
        let navController = UINavigationController(rootViewController: createAccounts)
        navController.modalPresentationStyle = .fullScreen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM