Completion block for popViewController

后端 未结 18 1638
离开以前
离开以前 2020-12-04 06:43

When dismissing a modal view controller using dismissViewController, there is the option to provide a completion block. Is there a similar equivalent for

18条回答
  •  囚心锁ツ
    2020-12-04 07:11

    Swift 3 answer, thanks to this answer: https://stackoverflow.com/a/28232570/3412567

        //MARK:UINavigationController Extension
    extension UINavigationController {
        //Same function as "popViewController", but allow us to know when this function ends
        func popViewControllerWithHandler(completion: @escaping ()->()) {
            CATransaction.begin()
            CATransaction.setCompletionBlock(completion)
            self.popViewController(animated: true)
            CATransaction.commit()
        }
        func pushViewController(viewController: UIViewController, completion: @escaping ()->()) {
            CATransaction.begin()
            CATransaction.setCompletionBlock(completion)
            self.pushViewController(viewController, animated: true)
            CATransaction.commit()
        }
    }
    

提交回复
热议问题