获取UISwitch状态-Xamarin

YKa*_*YKa 1 xamarin.ios ios

我正在使用Xamarin构建iOS应用程序.我环顾四周但却找不到确定UISwitch状态的方法.

我使用Storyboard创建了UI.交换机的Action名称是"Switch"

在我的FirstViewController中

        partial void Switch(NSObject sender)
        {
            // I am trying to find the state of the switch
            // here and then do something depending on its state
        }
Run Code Online (Sandbox Code Playgroud)

我试过去找发件人

string S=sender.ToString();
Run Code Online (Sandbox Code Playgroud)

我明白了:

S="<UISwitch: 0x14653dc0; frame = (61 425; 51 31); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x14653ea0>>"
Run Code Online (Sandbox Code Playgroud)

我还在Apple开发者网站上看到应该有一个isOn我可以检查但是无法弄清楚如何获得它.

干杯!

asp*_*net 11

只是用

bool state = ((UISwitch)sender).On;
Run Code Online (Sandbox Code Playgroud)

获得国家.