Search code examples
swiftwatchkit

Hierarchical Nav just to Main Controller in Apple WatchKit 2


I am building an app which moves between a set of controllers using:

self.pushControllerWithName("Scene A", context: nil)

Calling this will create a Back ability at the top that is ideal e.g. Main Scene -> Scene A -> Scene B -> Scene C, however how can I pop the whole stack back to Main Scene from Scene C in a "pop to beginning" type call? The only function I can see is this which only goes backwards one step.

self.popController()

Solution

  • There is also

    self.popToRootController()
    

    Discussion Use this method to return your interface to its initial configuration. You might do this so that you can reset your navigation hierarchy to its initial state before pushing one or more different interface controllers onto the navigation stack.

    Always call this method from your WatchKit extension’s main thread.

    Availability Available in iOS 8.2 and later.

    Reference Document