如何在 swift 5 中返回 rootview 控制器,其中可以使用场景而不是 Appdelegate
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 _ = (scene as? UIWindowScene) else { return }
if let windowScene = scene as? UIWindowScene {
self.window = UIWindow(windowScene: windowScene)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController =
storyboard.instantiateViewController(withIdentifier: "first_page")
self.window!.rootViewController = initialViewController
self.window!.makeKeyAndVisible()
}
}
这是我的场景代理代码需要关闭/弹出到我的第一页。
我在 Main.storyboard中有第一页,但我的注销功能在另一个名为Home.storyboard的故事板中
试过了
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
和
self.navigationController?.popToRootViewController(animated: true)
但不工作我只有一个导航控制器用于第一个视图控制器