How to hide navigation bar back button?

谁说我不能喝 提交于 2019-11-30 06:22:52
AMAN77

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.

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

WKInterfaceController.reloadRootControllersWithNames(["myInterfaceController"], contexts: [])
+ (void)reloadRootControllersWithNames:(NSArray *)names contexts:(NSArray *)contexts;

But you will lose the 'push' animation.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!