[英]How do I pass some value from one view controller to UINavigationController in swift 4 without using segue?
I want to pass value from one UIviewController to UINavigationViewController without using segue in swift 4. 我想将值从一个UIviewController传递给UINavigationViewController而不在swift 4中使用segue。
My sample code is following 我的示例代码如下
let vc = storyboard?.instantiateViewController(withIdentifier: "MainMenuId") as! UINavigationViewController
vc.sendValue = String //String send to sendValue which present in UINavigationController
self.present(vc!, animated: true, completion: nil)
But when I try to send at at that time my app is crashed and get error 但是当我当时尝试发送时,我的应用程序崩溃了,并报错
Could not cast value of type 'UINavigationController' to 'UIViewController' 无法将类型“ UINavigationController”的值转换为“ UIViewController”
So How do I pass value from above structure without using segue. 因此,如何不使用segue从上述结构传递值。 Thx in advance ;) 提前谢谢;)
You can use below code: 您可以使用以下代码:
let vc = storyboard?.instantiateViewController(withIdentifier:"MainMenuId") as! UIViewController
let nav = UINavigationController(rootViewController: vc)
vc.sendValue = String
self.present(nav!, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.