【发布时间】:2020-04-15 04:40:11
【问题描述】:
我有一个标签栏应用程序,在每个标签中都有一些显示转场。我希望能够从另一个选项卡栏中的操作中关闭一个选项卡栏中的视图控制器。
在我的示例中,当用户点击注销时,我想关闭每个选项卡中显示的所有视图控制器。
标签栏控制器是根视图控制器:
let tabBarController = self.window!.rootViewController as? UITabBarController
我不确定我哪里出错了,因为我尝试过的以下许多代码 sn-ps 对我不起作用...
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)
}
}
呈现的视图控制器仍在堆栈中。 我在这里有什么明显的遗漏吗?
【问题讨论】:
标签: swift