How to push uiViewcontroller?
Closed this issue · 4 comments
abhishekInvesto2o commented
How to push uiViewcontroller?
ferranabello commented
Hi @abhishekInvesto2o,
the answer is in the homepage:
Built-in router functions
This framework is very flexible, it's meant to be used in any way you want, but it has some useful built-in functionalities in the router that you could use:
//Show your module as the root view controller of the given window
func show(inWindow window: UIWindow?, embedInNavController: Bool, setupData: Any?, makeKeyAndVisible: Bool)
//Show your module from any given view controller
func show(from: UIViewController, embedInNavController: Bool, setupData: Any?)
//Show your module inside another view
func show(from containerView: UIViewController, insideView targetView: UIView, setupData: Any?)
//Present your module modally
func present(from: UIViewController, embedInNavController: Bool, presentationStyle: UIModalPresentationStyle, transitionStyle: UIModalTransitionStyle, setupData: Any?, completion: (() -> Void)?)
abhishekInvesto2o commented
Have used them. But don't they just present view controller instead of pushing inside navigationContoller? Can you just give me an example?
ferranabello commented
If your parent module view is not embedded in a a navigation controller then there is no way to push. To push a view controller you need a navigation controller. If not, it will try to present it as a modal.
So:
//Whatever drives your application
func startApplication() {
let window = UIApplication.shared.keyWindow
let parentModule = ApplicationModule.firstModule.build()
//Now you'll have your firstModule as the root of your app inside a UINavigationController
parentModule.router.show(inWindow: window, embedInNavController: true)
}
//And now some function to push to the second module
func goToSecondModule() {
let childModule = ApplicationModule.secondModule.build()
//Now we can push
childModule.router.show(from: parentModuleView)
}
abhishekInvesto2o commented
Thanks a lot. As you said I didn't instantiated navigationController at appDelegate.