iPhone - dismiss multiple ViewControllers

后端 未结 22 3056
粉色の甜心
粉色の甜心 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条回答
  •  萌比男神i
    2020-11-28 05:41

    A swift version with some additions based on this comment

    func dismissModalStack(viewController: UIViewController, animated: Bool, completionBlock: BasicBlock?) {
        if viewController.presentingViewController != nil {
            var vc = viewController.presentingViewController!
            while (vc.presentingViewController != nil) {
                vc = vc.presentingViewController!;
            }
            vc.dismissViewControllerAnimated(animated, completion: nil)
    
            if let c = completionBlock {
                c()
            }
        }
    }
    

提交回复
热议问题