UIViewController 未从 AppDelegate 呈现
UIViewController not presented from AppDelegate
如果用户尚未实例化,我正在尝试提供注册/登录 ViewController,但由于某种原因 ViewController 不想展示自己,它展示了一个黑色页面,上面什么也没有。这是我的 AppDelegate.swift
文件中的内容,如果用户尚未注册(我还没有注册),它应该显示 ViewController,我在 [=15= 中设置了一个断点]的ViewDidLoad()
没有命中。有人知道出了什么问题吗?
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
if Auth.auth().currentUser == nil {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let authVC = storyboard.instantiateViewController(identifier: "AuthVC")
window?.makeKeyAndVisible()
window?.rootViewController?.present(authVC, animated: true, completion: nil)
}
return true
}
如果您删除了场景委托
,则需要先创建window,然后再向其呈现任何内容
window = UIWindow(frame: UIScreen.main.bounds)
if let window = window {
window.rootViewController = UIViewController()
window.makeKeyAndVisible()
window.rootViewController?.present(authVC, animated: true, completion: nil)
}
对于 SceneDelegate
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
let navigationController = UINavigationController(rootViewController: UIViewController()) // instead of UIViewController() give it your application root controller... which you want to show when you dismiss presented controller
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
window?.rootViewController?.present(authVC, animated: true, completion: nil)
}
如果用户尚未实例化,我正在尝试提供注册/登录 ViewController,但由于某种原因 ViewController 不想展示自己,它展示了一个黑色页面,上面什么也没有。这是我的 AppDelegate.swift
文件中的内容,如果用户尚未注册(我还没有注册),它应该显示 ViewController,我在 [=15= 中设置了一个断点]的ViewDidLoad()
没有命中。有人知道出了什么问题吗?
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
FirebaseApp.configure()
if Auth.auth().currentUser == nil {
let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
let authVC = storyboard.instantiateViewController(identifier: "AuthVC")
window?.makeKeyAndVisible()
window?.rootViewController?.present(authVC, animated: true, completion: nil)
}
return true
}
如果您删除了场景委托
,则需要先创建window,然后再向其呈现任何内容window = UIWindow(frame: UIScreen.main.bounds)
if let window = window {
window.rootViewController = UIViewController()
window.makeKeyAndVisible()
window.rootViewController?.present(authVC, animated: true, completion: nil)
}
对于 SceneDelegate
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
let navigationController = UINavigationController(rootViewController: UIViewController()) // instead of UIViewController() give it your application root controller... which you want to show when you dismiss presented controller
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
window?.rootViewController?.present(authVC, animated: true, completion: nil)
}