Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Apple Watch API

khovekhove USMember


Is there any way to read out if a switch is turned on or off with the Xamarin API? Or the value of a Slider?
The "on" property has no getter according to the API-docs, and the example downloaded from github does not build (14 errors) so that is of no help at all.

Best Regards,


Best Answers


  • adamkempadamkemp USInsider, Developer Group Leader mod

    Do you mean this? There's definitely a getter. Which example are you trying?

  • khovekhove USMember

    Thats for the UISwitch from the UIKit, for Apple Watch it is only possible to use the WKInterfaceSwitch, witch only has set-method for On.

  • khovekhove USMember

    Sorry, my bad, will do it in the future ;)

    Ok, so my boolean-flag is the right way then, thanks.
    Do you have any good sugestions on how to keep track of the value a WKinterfaceSlider holds?

  • adamkempadamkemp USInsider, Developer Group Leader mod

    The same way you're keeping track of the other one. Whichever class is communicating with the Watch UI where that slider is needs to have a field to track the latest known value. When you get an update from the watch you update the field.

  • khovekhove USMember

    But how to do that without knowing if it is the left or right button that is pushed?

  • adamkempadamkemp USInsider, Developer Group Leader mod

    I don't understand your question. Each control in the WatchKit API has a way to set the value and a way to get notified of the value being changed by the user. That's all you need to keep track of the current value.

  • khovekhove USMember

    Do you mean the SetValueForKey() and ValueForKey() methods?

  • adamkempadamkemp USInsider, Developer Group Leader mod

    No. From the documentation:

    When the user changes the value of a slider, WatchKit delivers the new value to the slider’s action method.

    You set this up in interface builder.

  • khovekhove USMember

    Well, how will the action-method look then, because I have already tried some similar stuff without result. I have tried to add a action myAction: to the slider in the storyboard, but the only arbument it accepts is of the type WKInterfaceSlider with do not have a value attribute.

  • khovekhove USMember

    When I create an action in the designer (where they have done in this example it is removed on every build. And when I build the example from Xamarin again I get 14 or 15 errors, so it is of no help at all...

  • khovekhove USMember

    Thanks @adamkemp it worked! (pushed the wrong button and your reply disappeared, could you post it here again so I could mark it as a reply???)

    What happened for me is that I used the designer in Xamarin studio, and then i chose the slider, made an event called sliderAction and put the exact same method in the designer, but as it is written in the top of the designer:

    // This file has been generated automatically by Xamarin Studio from the outlets and
    // actions declared in your storyboard file.
    // Manual changes to this file will not be maintained.

    So it all disappeared when i build it. But this seems to work, so again, thanks!

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    It seems worthwhile to mention here. There is a bug in Xamarin's iOS Designer such that the wrong method signatures are generated for WatchKit controls. See the bug report:

    The iOS Designer team is aware of this issue and should be working to get it fixed.

  • khovekhove USMember

    Yes I know ;)
    It was filled becuase I sent an email to [email protected] and asked if this really was intentional or just an error, and seems I was wright, it was an error ;)

Sign In or Register to comment.