swift - 在 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
}
我无法进入入职或登录屏幕。我总是被引导到主屏幕。如果我在情节提要中手动将它们设置为初始视图控制器,我知道屏幕渲染得很好。
我尝试了许多解决方案,但都没有奏效。
解决方案
尝试这个:
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 语句的每个语句使用该代码,显然将视图控制器的名称分别更改为登录名称。
推荐阅读
- javascript - React js:为表格中的每个单元格设置状态
- google-cloud-platform - Google Compute Engine 是否支持发出 aiohttp 获取请求?
- python - 如何使用两个数组和引用将带有“interp1”的 Matlab 函数转换为带有“interp1d”的 Python
- json - 如何在 Json 中解码多/单值
- grails - 如何覆盖 grails 隐式日志变量
- java - mockMvc.perform 上的错误。空指针异常
- java - 在类 org.demo.mypackage1.C 中可以通过它们的短名称访问什么而不编写任何导入?
- php - 使用 php 变量设置 HTML 表格单元格标题
- python - 如何从单行字符串中查找子字符串
- asp.net-core - gRPC 适合推送通知吗?