ios - 注销具有多个情节提要 swift 5 的应用程序(返回根视图控制器)
问题描述
如何在 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)
但不工作我只有一个导航控制器用于第一个视图控制器
解决方案
尝试这个:-
let viewController = UIApplication.shared.windows.first!.rootViewController as!
YourViewController
然后使用这个viewController
推荐阅读
- xml - 在 xslt 中定义的工具 linux xsltproc 标记未写入输出 xml
- powerbi - 按最后状态分类的 DAX 总数
- ruby-on-rails - Rails 和 Active Storage,如何在创建调用时直接分配附件?
- paypal - 如果输入的第一张卡详细信息失败,则所有卡的每个 3D 安全性都失败
- python - 数据帧/列表/numpy元组数组的快速切片
- vue.js - 使用 createApp 传递道具
- amazon-web-services - 从主存储桶中删除 S3 对象(所有版本),同时将其复制到跨区域存储桶
- vb.net - 错误:由于以下错误,检索组件的 COM 类工厂失败:80070005 访问被拒绝
- react-native - 无法找到 RNReanimated 依赖的 React-callinvoker 规范
- amazon-sagemaker - 使用 boto3 调用 sagemaker 端点。抛出错误