gpt4 book ai didi

ios - Swift:通过 UITabBarController 呈现 viewController

转载 作者:行者123 更新时间:2023-11-28 12:11:36 25 4
gpt4 key购买 nike

我的应用程序完成启动后,如果当前用户未登录,我希望我的应用程序打开一个 LoginViewController。否则,它会转到一个 ViewController,它是在索引 0(默认值)处。因此,如果未登录,则在 UITabBarController 上显示模态视图。

我的初始 View Controller 是 UITabBarController,它是在 UIStoryboard 中创建的。它被选中标记为 Initial View 并以图形方式连接到其他五个 View Controller 。

实际上,我想我知道 LoginViewController 没有出现的原因。这是因为值结果为零(我在控制台中检查过)。但为什么??除了这种行为,一切都运行良好。 UITabBarController 似乎没有任何问题。

我的 LoginViewController 嵌入了 UINavigationViewController。此代码位于选定索引为 0 的 ViewController 中。它被放在 viewDidAppear() 方法中

 let main = UIStoryboard(name: "Main", bundle: nil)
let view = main.instantiateViewController(withIdentifier: "login") as! LoginViewController
let nav = UINavigationController(rootViewController: view)
self.tabBarController?.present(nav, animated: false, completion: nil)

但是,它不起作用。

最佳答案

如果用户未登录,则将窗口的 rootViewController 更改为 UINavigationController,如果他将其更改为 tabBarController

关于ios - Swift:通过 UITabBarController 呈现 viewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48316538/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com