Reputation: 441
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.
Upvotes: 3
Views: 16241
Reputation:
yout modal should be .fullScreen
Try with this:
let createAccounts = CreateAccounts();
let navController = UINavigationController(rootViewController: createAccounts)
navController.modalPresentationStyle = .fullScreen
Upvotes: 1
Reputation: 371
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
Upvotes: 6
Reputation: 422
// 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
Upvotes: 1