Chaudhry Talha
Chaudhry Talha

Reputation: 7868

How to hide navigation bar back button?

I'm trying to to hide navigation bar back button on an Apple Watch. There are a lot of questions for similar to mine but they are for iPhone and if you are know a little about Apple Watch there are InterfaceController instead of ViewController.

So when I push a new InterfaceController using the code below:

[self pushControllerWithName:@"about" context:nil];

It shows a back button on the navigation bar above and it takes it back to the previous InterfaceController from which it is generated.

Anyone have any idea how to hide or remove navigation bar or this back button from Apple Watch?

Upvotes: 20

Views: 4829

Answers (4)

infinite-loop
infinite-loop

Reputation: 902

Here is the Swift version for all the trailblazers out there:

WKInterfaceController.reloadRootControllersWithNames(["myInterfaceController"], contexts: [])

Upvotes: 5

AMAN77
AMAN77

Reputation: 6302

I had the same problem and solved it using :

NSMutableArray* controllerNames = [NSMutableArray new];
[controllerNames addObject:@"myInterfaceController"];
[WKInterfaceController reloadRootControllersWithNames:controllerNames contexts:myArrayOfData];

When the ICs are reloaded then they don't have navigation back buttons as they are the main IC.

Note

This method actually change your Initial Controller ( Main Interface Controller with arrow in storyboard.) of your watch app, that is the reason the Interface Controller does not have back button.

Upvotes: 10

foskon
foskon

Reputation: 51

+ (void)reloadRootControllersWithNames:(NSArray *)names contexts:(NSArray *)contexts;

But you will lose the 'push' animation.

Upvotes: 1

Jay
Jay

Reputation: 864

If you remove the back button, how are you planning to go back to previous screen?

This are my observations on navigation buttons in Apple Watch: Till now, we haven't found any method to over-ride the back-button title or remove it. Even they have provided option to add title, but no way to customize the font or anything. Most probably when Apple releases the original version they will provide all options.

UIKit and WK-kit In UIKit you can actually hide it using hidesbackbutton property, but in watch it will show you the previous interface controllers title. In UIKit, we are using UIViewController, but in Watch it is WKInterfaceController.

Inheritance

NSObject -> WKInterfaceController

NSObject -> UIResponder -> UIViewController

Upvotes: 0

Related Questions