[英]How to make the transition to a view controller with a navigation bar?
I have two modules that I need to connect. 我有两个模块需要连接。
How can I implement the transition in case of successful authorization from the authorization screen to the main application in Swift code? 如果从授权屏幕成功授权到Swift代码中的主应用程序,如何实现转换?
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.