不要移动UISwitch

时间:2013-10-17 09:08:48

标签: ios objective-c uiswitch

我想将UISwitch更改为关闭和关闭,但我不能。在xib中创建了UISwitch。

- (IBAction)switchAction:(id)sender {

    UISwitch *nkswitch = (UISwitch *)sender;
    if (nkswitch.isOn)
        NSLog(@"switchPressed ON");
    else
        NSLog(@"switchPressed OFF");

}

任何解决方案?

enter image description here

更新

enter image description here

2 个答案:

答案 0 :(得分:1)

我认为问题是你连接错误的UISwitch事件。签入Xibstoryboard。它与 ValueChange:的事件连接其他像: -

enter image description here

将UISwitch IBAction事件设置为UIControlEventValueChanged

答案 1 :(得分:1)

您的代码没有任何问题,您需要再次检查连接或删除UISwitch,添加新的连接并重新连接。