简体   繁体   English

如何使用导航栏转换到视图控制器?

[英]How to make the transition to a view controller with a navigation bar?

I have two modules that I need to connect. 我有两个模块需要连接。

  1. The authorization module, which consists of 1 screen. 授权模块,由1个屏幕组成。 There is no controller Navigation on it and it is not in its stack. 它上面没有控制器导航,它不在堆栈中。
  2. Main application. 主要应用。 The first screen is the root for the controller navigation. 第一个屏幕是控制器导航的根。

How can I implement the transition in case of successful authorization from the authorization screen to the main application in Swift code? 如果从授权屏幕成功授权到Swift代码中的主应用程序,如何实现转换?

My screen scheme 我的屏幕方案

SOLUTION: 解:

I use this solution for my case: 我在我的案例中使用此解决方案:

let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "rootVC")
        UIApplication.shared.delegate?.window??.rootViewController = vc
        view.present(vc, animated: true) {
            self.view.dismiss(animated: false, completion: nil)
        }

Give storyboardId "nav" to the Navigation Controller and then present it on your login view controller. 将storyboardId“nav”提供给导航控制器,然后将其显示在登录视图控制器上。

if let nav = self.storyboard?.instantiateViewController(withIdentifier: "nav") {
    self.present(nav, animated: true, completion: nil)
}

on your navigation Controller on storyboard add your storyboard Id, for example I have named it as navController 在您的导航控制器故事板上添加您的故事板ID,例如我将其命名为navController

在此输入图像描述

In your code, from you want to show as the navigation controller as present, add this line 在您的代码中,您希望将导航控制器显示为存在,添加此行

case if presented view Controller on same storyboard 如果在同一故事板上呈现视图控制器的情况

if let navController = self.storyboard?.instantiateViewController(withIdentifier: "navController") {
    self.present(navController, animated : true, completion : nil)
}

case if presented view controller on different storyboard 案例如果在不同的故事板上呈现视图控制器

let storyboard = UIStoryboard(name : STORYBOARD_NAME, bundle : nil)
let nav = storyboard.instantiateViewController(withIdentifier: "navController")
self.present(navController, animated : true, completion : nil)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 过渡到导航视图控制器 - Transition to a Navigation View Controller 如何使TableView控制器上的视图覆盖导航栏? - How to make a view on a TableView controller cover the navigation bar? 通过导航栏颜色的变化从一个视图控制器转换到另一个视图控制器 - Transition from one view controller to another with a change in colour of navigation bar 通过自定义过渡导航栏推送视图控制器时不会设置动画 - On pushing a view controller through custom transition navigation bar does not animate 如何隐藏导航控制器内部特定视图控制器上的导航栏 - How to hide navigation bar on a particular view controller inside of navigation controller 标签栏为初始视图控制器时,如何使“返回”按钮出现在导航控制器中 - How to make 'Back' button appear in Navigation Controller when Tab Bar is initial view controller Swift:如何从导航 Controller 过渡到标签栏控制器 - Swift: How to transition from Navigation Controller to Tab Bar Controler 如何从视图中删除导航栏 controller - How to remove navigation bar from view controller 如何在视图控制器上获取导航栏? - How to get the navigation bar on view controller? 切换到菜单栏中的视图控制器 - Transition to view controller in Menu Bar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM