6

In my Apple Watch app, one of my interface controllers has a Cancel button at the top left corner. In my case, once a particular action is completed, I don't want the user to go back to the previous screen, so I want to disable the user interaction for that Cancel button. Even if I change the title to an empty string, user interaction still stays enabled.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
simbesi.com
  • 1,539
  • 3
  • 17
  • 27

3 Answers3

18

We can't disable the back/cancel button user intaraction but can load controller without cancel button.

presentControllerWithName("NewInterfaceController", context: nil)

presentControllerWithName this will present controller with cancel button. If we use like below won't get the cancel button.

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

reloadRootControllersWithNames this will make our controller as a root controller so we won't get cancel button. This is how i resolved my issue. Hope it will help you as well.

NOTE: here [ ] is the syntax. exp: ["NewInterfaceController"]

simbesi.com
  • 1,539
  • 3
  • 17
  • 27
  • 'reloadRootControllers' was deprecated in watchOS 4.0: use reloadRootPageControllersWithNames. Also doesn't seem to work anymore as I'm still seeing the cancel button... – Robbie Jan 16 '20 at 22:06
1

You can't disable user interaction for back button.

But you can change a bit the way you present your views to accomplish what you want.

Start with your normal view. Check if you need to show the user the login. If you do, then present the login view Modally. At the end of login you close the modal view and you're back to normal view, without unnecessary back button.

pteofil
  • 4,133
  • 17
  • 27
  • then when login screen is visible user can dismiss and see my actual controller right? I think this doesn't work for me..! @pteofil – simbesi.com Jun 04 '15 at 12:52
  • I can continue to find solutions, but I think the main problem is that a login on the watch it's not part of the designed user cases for the watch. – pteofil Jun 04 '15 at 13:04
  • What you do on an iPhone app, is to tell the user that it needs to be logged on to use the app and a button to login. If the user tap login, you show the login view modally, and then when you close it you update the view with new content for logged in users. – pteofil Jun 04 '15 at 13:06
  • basically iam working on business application so providing login in apple watch as well and what you said is correct for iphone application. But in watch app user should not see the first screen which login or actual content screen. If you find any thing please share me. @pteofil – simbesi.com Jun 04 '15 at 13:23
0

This is simbesi.com's answer in watchOS 7/Swift 5.

Presenting the new controller modally:

presentController(withName: "NewInterfaceController", context: nil)

Presenting the new controller by replacing the root controller:

WKInterfaceController.reloadRootControllers(
    withNamesAndContexts: [
        (
            name: "NewInterfaceController",
            context: "NewInterfaceController" as AnyObject
        )
    ]
)
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223