Completion block for popViewController

后端 未结 18 1596
离开以前
离开以前 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:25

    Use the next extension on your code: (Swift 4)

    import UIKit
    
    extension UINavigationController {
    
        func popViewController(animated: Bool = true, completion: @escaping () -> Void) {
            CATransaction.begin()
            CATransaction.setCompletionBlock(completion)
            popViewController(animated: animated)
            CATransaction.commit()
        }
    
        func pushViewController(_ viewController: UIViewController, animated: Bool = true, completion: @escaping () -> Void) {
            CATransaction.begin()
            CATransaction.setCompletionBlock(completion)
            pushViewController(viewController, animated: animated)
            CATransaction.commit()
        }
    }
    

提交回复
热议问题