When dismissing a modal view controller using dismissViewController
, there is the option to provide a completion block. Is there a similar equivalent for
I made a Swift
version with extensions with @JorisKluivers answer.
This will call a completion closure after the animation is done for both push
and pop
.
extension UINavigationController {
func popViewControllerWithHandler(completion: ()->()) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
self.popViewControllerAnimated(true)
CATransaction.commit()
}
func pushViewController(viewController: UIViewController, completion: ()->()) {
CATransaction.begin()
CATransaction.setCompletionBlock(completion)
self.pushViewController(viewController, animated: true)
CATransaction.commit()
}
}