0
votes

I have a View(ViewController1) that overlays a modal ViewController2. ViewController2 has three options

  1. Delete all sessions
  2. Select a place
  3. Cancel

It's fairly easy to get to launch the modal viewController as this in ViewController1

  @objc func presentMenu() {
    let overlayController = ViewController2()
    overlayController.transitioningDelegate = self
    overlayController.modalPresentationStyle = .fullScreen
    present(overlayController, animated: true)
  }

This basically shows ViewController2. However viewController1 code has gone past this and where do I find out that this ViewController2 has been dismissed?

1

1 Answers

1
votes

You could implement viewWillAppear and try to figure out that the reason you're appearing is that the presented fullscreen view controller is being dismissed. But it would be even better to use the standard pattern where the presented fullscreen view controller tells you that it is being dismissed. To make that possible, it has a delegate, which you make sure is you:

overlayController.modalPresentationStyle = .fullScreen
overlayController.delegate = self
present(overlayController, animated: true)

Then the overlay controller calls a known method in its delegate when it is about to be dismissed:

self.delegate.dismissalIsHappening()

That method is usually defined by way of a protocol, which is why this is called the protocol and delegate pattern. I have not shown you the entire pattern! If you search on that term, you'll find lots of complete examples.