self.navigationController?.pushViewController not Working Swift

I think this problem is due to nil value of navigation stack for your CollectionViewController class. So, first of all go to storyboard and select CollectionViewController class and embed NavigationController into it. After this try and run it will work.

All the best.


In my case, I mistakenly added the MainViewController to the window.rootViewController instead of adding it to the UINavigationController and then using the navigation as rootViewController.

at SceneDelegate.swift, it should be:

 let navigationController = UINavigationController()
 navigationController.pushViewController(MainRouter.createModule(using: navigationController), animated: false)
 window.rootViewController = navigationController
 window.makeKeyAndVisible()

Tags:

Ios

Swift