推送特定的viewController

问题描述 投票:0回答:1

我有2个故事板,在故事板1中我有一个登录页面,在故事板2中,我有我的主页!所以问题出在我的主页面,我有退出按钮,当用户按下按钮我想回到我的登录页面时,我已经尝试了一些对我不起作用的方法!我试过了:

self.dismiss(animated: true, completion: nil)

和:

for controller in self.navigationController!.viewControllers as Array { if controller.isKind(of: ViewController) { self.navigationController!.popToViewController(controller, animated: true) break } }

那么,有什么办法可以回到我的登录页面吗?

ios swift uinavigationcontroller uistoryboard
1个回答
0
投票

由于您的代码不起作用,我认为您的登录视图控制器不在导航堆栈中。这是你可以尝试的。

let storyboard = UIStoryboard(name: "Login", bundle: nil)

if let loginViewController = storyboard.instantiateInitialViewController() {
    (UIApplication.shared.delegate as? AppDelegate)?.window?.rootViewController = loginViewController
}
© www.soinside.com 2019 - 2024. All rights reserved.