Kashif Ahmed
Kashif Ahmed

Reputation: 833

How to navigate to specific controller in navigation Controller

I am trying to navigate the second controller from the storyboard but the navigation bar is not showing on a controller. Actually I want to show controller from app delegates.

Here is my stack : enter image description here

here is my code:

             let storyboard = UIStoryboard(name: AppStoryboards.MAIN, bundle: Bundle.main)

                guard let controller = storyboard.instantiateViewController(withIdentifier: ViewControllerIdentifiers.THREAD_DETAIL_CONTROLLER) as? ThreadDetailController else {
                    return
                }

                controller.threadIdReceivedFromFeed = threadId as? String ?? String()

                self.window?.rootViewController = controller

here is actual result:

enter image description here

Upvotes: 0

Views: 422

Answers (1)

PGDev
PGDev

Reputation: 24341

You need to use add the controller as the rootViewController of the UINavigationController and then set that navigationController as window's rootViewController, i.e.

    let storyboard = UIStoryboard(name: AppStoryboards.MAIN, bundle: nil)

    if let controller = storyboard.instantiateViewController(withIdentifier: ViewControllerIdentifiers.THREAD_DETAIL_CONTROLLER) as? ThreadDetailController {
        controller.threadIdReceivedFromFeed = (threadId as? String) ?? ""
        let navigationController = UINavigationController(rootViewController: controller) //here...
        self.window?.rootViewController = navigationController
    }

Upvotes: 1

Related Questions