Completion block for popViewController

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

    For 2018 ...

    if you have this ...

        navigationController?.popViewController(animated: false)
        // I want this to happen next, help! ->
        nextStep()
    

    and you want to add a completion ...

        CATransaction.begin()
        navigationController?.popViewController(animated: true)
        CATransaction.setCompletionBlock({ [weak self] in
           self?.nextStep() })
        CATransaction.commit()
    

    it's that simple.

    Handy tip...

    It's the same deal for the handy popToViewController call.

    A typical thing is you have an onboarding stack of a zillion screens. When finally done, you go all the way back to your "base" screen, and then finally fire up the app.

    So in the "base" screen, to go "all the way back", popToViewController(self

    func onboardingStackFinallyComplete() {
        
        CATransaction.begin()
        navigationController?.popToViewController(self, animated: false)
        CATransaction.setCompletionBlock({ [weak self] in
            guard let self = self else { return }
            .. actually launch the main part of the app
        })
        CATransaction.commit()
    }
    

提交回复
热议问题