gpt4 book ai didi

swift - 在 AppDelegate 中设置初始 View Controller 时完全黑屏

转载 作者:行者123 更新时间:2023-12-02 05:18:17 41 4
gpt4 key购买 nike

我想做的就是在用户= nil 的情况下进入登录屏幕。否则,它将转到应用程序的主/主页部分,其中包含选项卡栏 Controller 的第一个 View Controller

这是我的应用程序委托(delegate):

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
}

我无法进入入门或登录屏幕。我总是被引导到主屏幕。我知道如果我手动将它们设置为 Storyboard中的初始 View Controller ,屏幕渲染得很好。

我尝试了多种解决方案,但没有一个有效。

更新 enter image description here

最佳答案

试试这个:

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 语句的每个语句使用该代码,显然将 View Controller 的名称分别更改为登录 Controller 。

关于swift - 在 AppDelegate 中设置初始 View Controller 时完全黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59806073/

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