How do you present a view controller embedded in a navigation controller through the App Delegate?

Hello,


I am playing around with adding 3D Touch quick actions to my app, and I need one of them to take the user to a view controller that is embedded in a navigation controller. Let me explain:


Navigation Controller -> Main Page View Controller -> The View Controller I need to get to


I have tried many things to try to get this to work. First, I tried presenting the view controller I need to get to (Let's call it "ViewController") straight from the App Delegate, where the 3D Touch quick actions get "received", so to say. That worked originally, but the navigation bar wasn't there, so you couldn't get back to the MainViewController (In the example it is called "Main Page View Controller").


Then, I tried presenting the MainViewController, and from there presenting ViewController. That didn't work, there still wasn't a nav bar. Lastly, I tried presenting the Navigation Controller, and then presenting the MainViewController form there, and presenting ViewController from the MainViewController to no avail.


This is the function in the AppDelegate I'm trying to present ViewController from

@available(iOS 9.0, *)
    func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        if shortcutItem.type == "com.hp.Userword-Username-And-Password-Generator.generatePassword" {
          //Where to run the code to get to ViewController
     }
}    


Is there anyone who knows how to do this? Thanks in advance. Any help is appreciated.

Did you watch Stanford course for IOS ?

developing for IOS10 with Swift, accessible on iTunes University


LEssons 5 or 6 I remember, that could help you.

>> a view controller embedded in a navigation controller


"Embedded" doesn't mean what you seem to be asking for:


>> …but the navigation bar wasn't there, so you couldn't get back to the MainViewController


So you want a Back button that goes back from the ViewController to the MainViewController? In that case, you need to push the ViewController onto the navigation view controller's stack. Use the UINavigationController's "pushViewController(_:animated:)" method.

Typically, in your example, an 'unwind segue' is your friend, I think.


See Technical Note TN2298: Using Unwind Segues

So if I added the MainViewController and the ViewController onto the Navigation Controller's stack, how would I present the ViewController?

Pushing it onto the nav view controller's stack presents it. If you read the documentation for the method (https://developer.apple.com/documentation/uikit/uinavigationcontroller/1621887-pushviewcontroller), it's explained:


"Pushes a view controller onto the receiver’s stack and updates the display. … In addition to displaying the view associated with the new view controller at the top of the stack, this method also updates the navigation bar and tool bar accordingly."


Is there something else you expect to happen?

How do you present a view controller embedded in a navigation controller through the App Delegate?
 
 
Q