I have two View Controllers:
MainController.swift
- Soryboard less view controller SecondController.swift
- Storyboard view controller How can I instantiate SecondController
in MainController
?
storyboard?.instantiateViewController(withIdentifier: _)
does not work because MainController has no storyboard.
How can I open SecondController in MainController?
It depends what “open” means. You can, for example, say
present(SecondController(), animated:true)
Or you might push it onto a navigation controller if there is one in the interface. That sort of thing, and similar, are quite standard. Storyboards are a relatively recent innovation; when I started programming iOS everything was done without them.
Use init(name:bundle:) :
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let secondVC = storyboard.instantiateViewController(withIdentifier: "SecondController") as! SecondController
If you want to see example usage in an app then take a look at this file .
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.