Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What function is called when a UIViewController is back in focus?

Tags:

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

enter image description here

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 ...")
    }
}
like image 440
jamesMcKey Avatar asked Aug 28 '18 13:08

jamesMcKey


People also ask

What is UIViewController life cycle?

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.

When loadView is called?

* 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.

What is the difference between ViewController and UIViewController?

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.

What is Viewdidlayoutsubviews?

Called to notify the view controller that its view has just laid out its subviews.


1 Answers

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)
  }
}
like image 94
Sh_Khan Avatar answered Sep 28 '22 05:09

Sh_Khan