swift - 从 iOS 13 Beta 3 开始,我的应用只显示黑色窗口
问题描述
这是我的场景委托方法的代码:
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).
// Use a UIHostingController as window root view controller
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
// Override point for customization after application launch.
let context = AppDelegate.shared.persistentContainer.viewContext
context.automaticallyMergesChangesFromParent = true
window.rootViewController = UIHostingController(rootView: ContentView())
self.window = window
window.makeKeyAndVisible()
}
解决方案
这是最初的默认值。从 beta 3 开始,windows 需要像这样初始化:
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: ContentView(coordinator:coord, model:store))
self.window = window
window.makeKeyAndVisible()
}
推荐阅读
- python - 在python中将日期时间写入CSV文件?
- reactjs - 添加导入对象时的括号表示法
- php - 从 API 获取 json 数据,如何以表格格式或引导程序在循环中显示数据
- amazon-web-services - 潜望镜式应用架构
- java - 日食氧气 (4.7) 中无法通过 JMC 6 启动飞行记录器
- node.js - node.js Https 调用返回未定义。亚马逊AWS
- typescript - 我想在打字稿中打开一个查询?
- r - R - geom_bar 带有分组标签的分组条形图
- visual-studio - 是否有任何自动化方法可以在 TFS 2018 中创建集合和项目
- angular - 带有 AOT 编译器的 NGRX angular 5 减速器