[英]Segue from one view controller embedded within UINavigationController to another UINavigationController
[英]How do I pass some value from one view controller to UINavigationController in swift 4 without using segue?
我想将值从一个UIviewController传递给UINavigationViewController而不在swift 4中使用segue。
我的示例代码如下
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)
但是当我当时尝试发送时,我的应用程序崩溃了,并报错
无法将类型“ UINavigationController”的值转换为“ UIViewController”
因此,如何不使用segue从上述结构传递值。 提前谢谢;)
您可以使用以下代码:
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.