I want to pass value from one UIviewController to UINavigationViewController without using segue in swift 4.
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'
So How do I pass value from above structure without using 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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.