Search code examples
swifttriggersuinavigationcontrollerviewcontrolleruisplitviewcontroller

Swift 3 - Trigger pushViewController from other viewcontroller


currently i am in my custom split view controller which extends from UISplitViewController and i want to trigger a pushViewController in the master viewcontroller of it:

(self.splitViewController?.viewControllers.first as! MasterViewController).navigationController?.pushViewController(viewControllerObject, animated: true)

But my app just crashes.. could anybody help me out?

Thanks and Greetings!


Solution

  • Well I believe it's just a syntax issue. The first view controller of your split view controller is probably just the navigation controller.

    (self.splitViewController?.viewControllers.first as! UINavigationController).pushViewController(viewControllerObject, animated: true)
    

    Should work.