繁体   English   中英

从 ViewController 导航到另一个 ViewController

[英]Navigating from ViewController to another ViewController

我是 iOS 开发的新手。 我有一个已经开发的应用程序。 我进行了更改,但我无法以编程方式使用推送/替换/呈现以及有或没有英雄 package 从 ViewController 导航到另一个 ViewController。 它们都不起作用!

我有两个故事板,每个都有多个 ViewController。

这就是我在 AppDelegate 中所做的:

self.window?.rootViewController = UIStoryboard(name: "Auth", bundle: nil).instantiateInitialViewController()
self.window?.makeKeyAndVisible()

这就是我导航的方式:

guard let registerViewController = UIStoryboard(name: "Auth", bundle: .main)
                                   .instantiateViewController(withIdentifier: "RegisterViewController")
                                   as? RegisterViewController else { return }
self.navigationController?.pushViewController(registerViewController, animated: true)

我不想使用 Storyboard 链接链接这些 ViewController,因为有时我需要在移动到另一个 ViewController 之前根据条件进行异步操作或导航

我在这里做错了吗?

**To navigate from one controller to another, you have to make navigation controller as a rootViewController as shown below:-** 

    let authVC = UIStoryboard(name: "Auth", bundle: nil).instantiateInitialViewController()
    let nav = UINavigationController(rootViewController: authVC)
    self.window?.rootViewController = nav
    self.window?.makeKeyAndVisible()

我通过在Auth storyboard 中添加NavigationController来解决它,或者以编程方式使用UINavgiationController作为@Nexus 的答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM