iPhone - dismiss multiple ViewControllers

后端 未结 22 3063
粉色の甜心
粉色の甜心 2020-11-28 04:46

I have a long View Controllers hierarchy;

in the first View Controller I use this code:

SecondViewController *svc = [[SecondViewController alloc] i         


        
22条回答
  •  Happy的楠姐
    2020-11-28 05:24

    Simple recursive closer:

    extension UIViewController {
        final public func dismissEntireStackAndSelf(animate: Bool = true) {
            // Always false on non-calling controller
            presentedViewController?.ip_dismissEntireStackAndSelf(false)
            self.dismissViewControllerAnimated(animate, completion: nil)
        }
    }
    

    This will force close every child controller and then only animate self. You can toggle for whatever you like, but if you animate each controller they go one by one and it's slow.

    Call

    baseController.dismissEntireStackAndSelf()
    

提交回复
热议问题