1

首先显示 AuthViewController(又名 root),然后显示带有 tabBarController 的黑屏,但上面没有项目。

可能是什么问题呢?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let windowScene = (scene as? UIWindowScene) else { return }
        window = UIWindow(frame: UIScreen.main.bounds)
        window?.windowScene = windowScene

        if let user = Auth.auth().currentUser {
            FirestoreServices.shared.getUserData(user: user) { (result) in
                switch result {
                case .success(let muser):
                    let mainTabBar = MainTabBarViewController()
                    mainTabBar.currentUser = muser
                    mainTabBar.modalPresentationStyle = .fullScreen
                    self.window?.rootViewController = mainTabBar
                case .failure(_):
                    self.window?.rootViewController = AuthViewController()
                }
            }
        } else {
            self.window?.rootViewController = AuthViewController()
        }
        window?.makeKeyAndVisible()
    } 
4

1 回答 1

0

编辑:您需要从情节提要实例化,因为您正在使用情节提要。您需要使用windowScene 初始化您的窗口变量window。

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {

        guard let windowScene = (scene as? UIWindowScene) else { return }

        window = UIWindow(windowScene: windowScene)
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        if let user = Auth.auth().currentUser {
            FirestoreServices.shared.getUserData(user: user) { (result) in
                switch result {
                case .success(let muser):
                    let mainTabBar = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! TabViewController
                    mainTabBar.currentUser = muser
                    mainTabBar.modalPresentationStyle = .fullScreen
                    self.window?.rootViewController = mainTabBar
                    print("BLA BLA \(String(describing: self.window?.frame))")
                case .failure(_):
                    let authVC = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! AuthViewController
                    self.window?.rootViewController = authVC
                }
            }
        } else {
            let authVC = storyboard.instantiateViewController(withIdentifier: "viewControllerIDInStoryboard") as! AuthViewController
            self.window?.rootViewController = authVC
        }
        window?.makeKeyAndVisible()
    } 
于 2020-06-13T01:28:22.270 回答