将视图控制器更改为特定视图控制器

Clo*_*loy 5 ios swift

我的视图控制器登录->主菜单-> A-> B-> C-> D

如何取消所有视图控制器并返回主菜单

对于从我的视图控制器注销,我正在执行以下操作,返回到“登录”

func logout{

    self.view.window!.rootViewController?.dismissViewControllerAnimated(false, completion: nil)
 }
Run Code Online (Sandbox Code Playgroud)

现在我正在做的是

class AppDelegate: UIResponder, UIApplicationDelegate {
     var viewControllerStack: [BaseViewController]!
}

override func viewDidLoad() {
    super.viewDidLoad()
    super.appDelegateBase.viewControllerStack.append(self)  
}

func go_To_MainMenu(){
    var countOfNumberOfViewCOntrollers = self.appDelegateBase.viewControllerStack.count 

        switch countOfNumberOfViewCOntrollers{

             self.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
            break;
        case 2:

            self.presentingViewController?.presentingViewController?.presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
            break;
   }
}
Run Code Online (Sandbox Code Playgroud)

Poc*_*chi 5

如果MainMenu VC总是在登录VC之后出现,则可以简单地使用相同的方法:

到MainMenu:

self.view.window!.rootViewController?.presentedViewController?.dismissViewControllerAnimated(true, completion: nil)
Run Code Online (Sandbox Code Playgroud)