0

I've been searching for a solution for this since yesterday. Everything I could find was suggested 4-5 iOS versions ago, and seems to not work anymore. I was wondering if anyone has a new, working idea?

Adding the two different suggestions I found:

func popViewController(animated: Bool, completion: @escaping () -> Void) {
      popViewController(animated: animated)
      if animated, let coordinator = transitionCoordinator {
          coordinator.animate(alongsideTransition: nil) { _ in
             completion()
          }
      } else {
          completion()
      }
}

And

func popViewControllerWithHandler(completion: ()->()) {
        CATransaction.begin()
        CATransaction.setCompletionBlock(completion)
        self.popViewControllerAnimated(true)
        CATransaction.commit()
}

What's the reason UIKit doesn't offer it? So weird

Yotam
  • 9,789
  • 13
  • 47
  • 68

1 Answers1

0

Try this way, you can conform your controller class to UINavigationControllerDelegate and implement didShow ViewController method:

class YourController: UIViewController, UINavigationControllerDelegate ...

in viewDidLoad set navigation controller delegate to self

navigationController?.delegate = self

after that use navigation controller didShow method like that:

func navigationController(_ navigationController: UINavigationController, didShow viewController: UIViewController, animated: Bool) {
    // your completion code here
    print("completion block")
 }
Fabio
  • 5,432
  • 4
  • 22
  • 24