I have single view application that also presents a custom popup which I have made using another viewController. The popup viewController has the following assigned:
presentation: Over current context
when it is presented. When I dismiss this popup viewController to show the first viewController, I would like to know what function gets called so that I can do more stuff within that function. I have tested the following functions below but none of them are called when I have dismissed the popup to reveal the first viewController.
class firstViewController: UIViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print("viewWillAppear PdfViewController...")
}
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad PdfViewController ...")
}
}
The LifecycleThe view controller lifecycle can be divided into two big phases: the view loading and the view lifecycle. The view controller creates its view the first time the view is accessed, loading it with all the data it requires. This process is the view loading.
* If the view is not currently in memory, the view controller calls its loadView. method. 3. * The loadView method does one of the following: If you override this method, your implementation is. responsible for creating all necessary views and assigning a non-nil value to the view property.
Both are used for different purpose. A UIViewController class manages a ViewContoller which is responsible for actions that happen within that View controller. This class is aware of actions that happen on view controller, like ViewDidLoad, ViewWillApper, ViewDidAppear, ViewWillDisapper, ViewDidDisapper.
Called to notify the view controller that its view has just laid out its subviews.
This depends on the style overCurrentContext
doesn't call viewWillAppear
/viewDidAppear
, for example fullScreen
does , look here for all possible styles
https://developer.apple.com/documentation/uikit/uimodalpresentationstyle
if the selected one doesn't call the method then implement delegate for that when you dismiss the modal
//
protocol DimissManager {
func vcDismissed()
}
class FirstVc:UIViewController,DimissManager {
func vcDismissed() {
print("Dismissed")
}
func showSecond() {
let sec = storyboard
sec.delegate = self ...... // note this assign may be in prepareForSegue if you use segues
self.present(sec.......
}
}
class SecondVc:UIViewController{
var delegate:DimissManager?
@IBAction func dismiss(_ sender:UIButton) {
delegate?.vcDismissed()
self.dismiss(animated:true,completion:nil)
}
}
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