gpt4 book ai didi

ios - 将 UITabBarController 设置为 rootViewController

转载 作者:搜寻专家 更新时间:2023-11-01 06:26:20 24 4
gpt4 key购买 nike

我有一个 UITabBarController,如果用户 session 仍处于事件状态,我想显示此屏幕而不是登录屏幕。

我的 UITabBarController 有 3 个 ViewControllers,问题是我没有看到底部的 TabBar 链接,我无法访问导航。

enter image description here

没有下面的代码一切正常。我的意思是登录后我可以导航。

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.

FirebaseApp.configure()

if Auth.auth().currentUser != nil {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = HomeTabBarController()
}

return true
}

我也试过下面的代码来设置 rootViewController 但这是同样的问题。

当我尝试将其他 View Controller 之一设置为根(其中一个 subview Controller )时,标签栏根本不显示

var rootView: MyRootViewController = MyRootViewController()

if let window = self.window{
window.rootViewController = rootView
}

我在这里做错了什么?

enter image description here

最佳答案

我遇到了同样的问题,我看到了你的帖子,你的代码的问题是 HomeTabBarController() 正在创建一个全新的 TabBarController 所以要修复它,请尝试我使用的以下方法。

if Auth.auth().currentUser != nil {

print("******************************User Present******************************")
self.window = UIWindow(frame: UIScreen.main.bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)

// create view controllers from storyboard
// Interface Builder -> Identitiy Inspector -> Storyboard ID
// Set up the Tab Bar Controller to have two tabs
let tabBarController = storyboard.instantiateViewController(withIdentifier: "HomeTabBarController") as! HomeTabBarController
// Make the Tab Bar Controller the root view controller
window?.rootViewController = tabBarController
window?.makeKeyAndVisible()
}

编辑 确保将标识符添加到您的 TabBarController

    // Interface Builder -> Identitiy Inspector -> Storyboard ID

关于ios - 将 UITabBarController 设置为 rootViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54015256/

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