1
votes

I have a function inside my app delegate which is supposed to push a View Controller when called from a Siri Shortcut.

func pushNewView() {
    if let wind = UIApplication.shared.delegate?.window {
        if let rootViewController = wind?.rootViewController {
            let viewToPush = TripTableViewController()
            if let alreadySomeOneThere = rootViewController.presentedViewController {
                alreadySomeOneThere.navigationController?.pushViewController(viewToPush, animated: true)
            } else {
                rootViewController.navigationController?.pushViewController(viewToPush, animated: true)
            }
        }
    }
}

When I called pushNewView() from my AppDelegate, nothing happens.

If I present the view controller instead of pushing it, that does work but I want the view controller pushed.

I'm not using any storyboards, all my code is programmatic.

Does anyone know how to make this function successfully push the View Controller?

1
as your description 'rootViewController' don't have 'UINavigationController' as container, so embed rootViewController to navigationController. - Rocky

1 Answers

1
votes

Nothing is happening because neither alreadySomeOneThere nor rootViewController are embedded in a navigation controller.

In order to push another view controller, there needs to be an existing navigation controller in place.

You need to do one of two things. Either redo your setup such that alreadySomeOneThere and rootViewController are embedded in a navigation controller, or you need to present the new view controller from alreadySomeOneThere or rootViewController.

Please note that you can't push a navigation controller. If you choose to put alreadySomeOneThere and rootViewController in a navigation controller, then just push viewToPush. Don't create another navigation controller.

If you instead decide to present the new view controller from alreadySomeOneThere or rootViewController, then depending on the needs of viewToPush, you may or may not need viewToPush embedded its own navigation controller.