I am presenting a view controller from a view controller called HomeController like so:
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginController") as! LoginController let navigationController: UINavigationController = UINavigationController(rootViewController: viewController) present(navigationController, animated: true, completion: nil)
In the presented view controller LoginController at some point gets dismissed:
self.dismiss(animated: true, completion: nil)
But when it comes back to HomeController it is not calling viewWillAppear, I really need to check on condition on HomeController when it comes back to it, So how can I call viewWillAppear when LoginController dismisses the view?
In other words, if someone looks at another application or takes a phone call, then switches back to your app which was earlier on backgrounded, your UIViewController which was already visible when you left your app 'doesn't care' so to speak -- as far as it is concerned, it's never disappeared and it's still visible ...
The method viewWillAppear: is triggered in response to a change in the state of the application, indicating that the view controller is becoming “active.” The reason viewDidLoad exists – the only reason – is that it sometimes isn't possible or efficient to configure 100% of an interface in a XIB.
If both these methods are called, what's the difference between the two? viewDidLoad() is only called once, when the view is loaded from a . storyboard file. viewWillAppear(_:) is called every time the view appears.
viewWillAppear(_:)Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called.
You need to set the correct presentationStyle. If you want that your presentedController will be fullScreen and call it the previous viewWillAppear, then you can use ".fullScreen"
let viewController = self.storyboard?.instantiateViewController(withIdentifier: "LoginController") as! LoginController let navigationController: UINavigationController = UINavigationController(rootViewController: viewController) navigationController.modalPresentationStyle = .fullScreen present(navigationController, animated: true, completion: nil)
In iOS 13 , if you are presenting a view controller and when you are coming back viewWillAppear doesn't get called . I have changed it from present to push view controller and methods are getting called now .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With