Ross Michael
Ross Michael

Reputation: 1

UINavigationController in Watchkit

Is there a way to control the navigation bar in WatchOS similar to how we can control it in iOS using UINavigationController?

What I am trying to do is hide the navigation bar for certain WKInterfaceControllers and show it for others. What I am able to do so far is hiding the navigation bar for the entire WatchOS app.

Upvotes: 0

Views: 619

Answers (1)

Asol
Asol

Reputation: 359

What do you exactly mean by hiding NavigationBar for WKInterfaceController?

As we know in Apple Watch, there are two ways to navigate between Interface Controllers:

  • Hierarchical (adding scenes to the stack)

Pushes another Interface Controller on the screen

  • Page-based (presenting scenes modally)

Displays another Interface Controller on top of the current Interface Controller.

The Apple Documentation says that

The navigation bar appears at the top edge of the Apple Watch screen. The system displays the clock at one end of the navigation bar and provides a title area at the opposite end. The title area can also include navigational elements such as a Back Button or a Dismiss Button.

IMPORTANT: The clock appears in the navigation bar of every nonmodal app screen. You can’t remove the clock, so be sure to account for it in your designs.

I wrote this to came to the conclusion that you want to remove the Back Button, correct? If so, you may try this:

WKInterfaceController.reloadRootPageControllers(withNames: ["DestinationInterfaceController"], contexts: nil, orientation: .horizontal, pageIndex: 0)

In the DestinationInterfaceController, you should put the identifier of the destination Interface Controller.

Upvotes: 1

Related Questions