首页 > 解决方案 > 在 AppDelegate 中设置初始视图控制器时完全黑屏

问题描述

如果用户= nil,我要做的就是转到登录屏幕。否则它会转到应用程序的主/主页部分,该部分由标签栏控制器的第一个视图控制器组成

这是我的应用程序委托:

import UIKit
import Firebase

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    FirebaseApp.configure()
    let storyboard = UIStoryboard(name: "Main", bundle: nil)

    if Auth.auth().currentUser == nil && !UserDefaults.standard.bool(forKey: "hasViewedWalkthrough") {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "WalkthroughViewController") as? WalkthroughViewController
        self.window?.rootViewController = initialViewController


    } else if Auth.auth().currentUser == nil && UserDefaults.standard.bool(forKey: "hasViewedWalkthrough") {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "loginViewController") as? LoginViewController
        self.window?.rootViewController = initialViewController

    } else {

        let initialViewController = storyboard.instantiateViewController(withIdentifier: "homeTabBarController") as? MainTabBarViewController
        self.window?.rootViewController = initialViewController

    }

    self.window?.makeKeyAndVisible()
    return true
}

我无法进入入职或登录屏幕。我总是被引导到主屏幕。如果我在情节提要中手动将它们设置为初始视图控制器,我知道屏幕渲染得很好。

我尝试了许多解决方案,但都没有奏效。

更新 在此处输入图像描述

标签: swiftfirebasefirebase-authentication

解决方案


尝试这个:

let storyBoard = UIStoryboard(name: "Main", bundle: nil)
        let initialViewController = storyBoard.instantiateViewControllerWithIdentifier("homeTabBarController") as? TabBarViewController // whatever your swift file is called 
        self.window?.rootViewController = storyBoard

为 if 语句的每个语句使用该代码,显然将视图控制器的名称分别更改为登录名称。


推荐阅读