ios - AppDelegate 未提供 UIViewController
问题描述
如果用户尚未实例化,我正在尝试显示注册/登录 ViewController,但由于某种原因,ViewController 不想显示自己,它显示的是一个黑色页面,上面没有任何内容。这是我的AppDelegate.swift
文件中的内容,如果用户尚未注册(我还没有),它应该显示 ViewController,我在 VC 中设置了一个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 = UIWindow(frame: UIScreen.main.bounds)
if let window = window {
window.rootViewController = UIViewController()
window.makeKeyAndVisible()
window.rootViewController?.present(authVC, animated: true, completion: nil)
}
对于场景委托
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)
}
推荐阅读
- python - 在 Jupyter Notebook 中使用 Python 基于多个容差值对单个数据框单元格进行 Pandas 颜色编码
- java - JSON 字符串无法转换为数组/ArrayList
- javascript - 如何在角度上使用 formatDate 格式化日期
- xamarin.forms - 在 Xamarin.Forms Shell 中隐藏 tabbedPage 的标题
- flutter - 在 Flutter 中使用带有 WillPopScope 的嵌套导航器
- java - 如何将带有“/”符号的值作为获取参数传递给我的控制器?
- android - 如何使用相同的模型将列表<>中的项目添加到另一个列表<>
- javascript - 如何将事件设置为使用 .classList.add 添加类的选择器
- python-3.x - 如何通过修改请求自动修改 hr.attendance 的字段
- java - 从 kafka 流和 Avro 反序列化的同一类上的 ClassCastException