I have a tab bar application that has some show segue's in each tab. I would like to be able to dismiss the view controllers from one tab bar from an action in another tab bar.
In my example, when a user taps log-out, I want to dismiss all the presented view controllers in each of the tabs.
The tab bar controller is the root view controller:
let tabBarController = self.window!.rootViewController as? UITabBarController
I'm not sure where I'm going wrong as many of the following code snippets that I have tried do not work for me...
self.navigationController?.popToRootViewController(animated: true)
self.view.window?.rootViewController?.dismiss(animated: false, completion: nil) //doesn't dismiss presented VC's on other tab bar controller
UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: false, completion: nil)
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
dismissViewControllers()
dismiss(animated: false, completion: nil)
}
func dismissViewControllers() {
guard let vc = self.presentingViewController else { return }
while (vc.presentingViewController != nil) {
vc.dismiss(animated: true, completion: nil)
}
}
The presented view controllers are still on the stack. Is there anything obvious that I am missing here?