Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - Remote Notifications and Navigation Controller Flow

I am setting up Push Notifications that I will send to the device with some data, and I want to load a certain view on the navigation controller stack. However, I want to keep the navigation stack intact, i.e. the destination view controller should still have a navigation bar with back button to go backwards to previous view controller, etc.

Flow: Navigation Controller -> Root View Controller -> Destination Controller.

How can I go about displaying a specific, non-root, view controller in a UINavigationController stack without losing hierarchy and functionality?

Right now I am doing this and it shows the View Controller properly, but no navigation bar:

        let idPushNotification = userInfo["idPushNotification"] as String
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let destinationViewController = storyboard.instantiateViewControllerWithIdentifier("DestinationViewController") as DestinationViewController
        destinationViewController.idPushNotification = idPushNotification.toInt()!

        let navigationController = self.window?.destinationViewController;
        navigationController?.presentViewController(destinationViewController, animated: false, completion: nil)
like image 751
JimmyJammed Avatar asked Dec 01 '25 14:12

JimmyJammed


1 Answers

You are presenting the view controller so it will not show any navigationBar.You need pushViewController on navigation stack

    let navigationController:UINavigationController = self.window?.destinationViewController as UINavigationController;
    navigationController?.pushViewController(destinationViewController, animated: false)
like image 54
codester Avatar answered Dec 04 '25 04:12

codester



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!