我正在使用 Xcode 11 (beta3) 并为 iOS 13 构建应用程序。在我的项目中,我创建了用于UIWindowSceneDelegate
在 Info.plist 中声明它的委托方法。现在我可以创建多个窗口(和 UIScene)。
现在我没有一个窗口了,如何访问 rootViewController?我需要它来获取对它所拥有的对象和边界的一些引用。
在我的 AppDelegatewindow is nil
和我的 ViewController (子视图控制器)实例中,我尝试使用self.view.window.rootViewController
但我发现这viewDidLoad()
为时过早(我认为)并且窗口仍然为零,可以工作viewDidAppear()
,但我不需要每次都进行此过程视图控制器出现的时间。
这种处理应用场景的新方法的最佳实践是什么?
这是我的 AppDelegate:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
return true
}
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
我的场景委托:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// yes it's empty, I'm using storyboard
}