使用故事板时带有 sceneDelegate 的黑屏
black screen with sceneDelegate when using storyboard
首先显示 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()
}
编辑:您需要从故事板实例化,因为您正在使用故事板。
您需要使用 windowScene.
初始化 window 变量 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()
}
首先显示 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()
}
编辑:您需要从故事板实例化,因为您正在使用故事板。 您需要使用 windowScene.
初始化 window 变量 windowvar 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()
}