문제

I want to change the UISwitch on to off and off to on, but I can't. Created the UISwitch in xib.

- (IBAction)switchAction:(id)sender {

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

}

Any solution?

enter image description here

Update

enter image description here

도움이 되었습니까?

해결책

i think the problem is you are connect wrong Event of UISwitch. check in Xib or storyboard. it is connect with Event of ValueChange: insted of Other like:-

enter image description here

Set the UISwitch IBAction Event to UIControlEventValueChanged

다른 팁

There's nothing wrong in your code,you need to check your connection again or remove your UISwitch,add new one and reconnect.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top