开发者

UISwitch not returning its current state (on/off)

Here is the IBAction method linked to the UISwitch with the valueChanged event :

- (IBAction) sanitySwitch {
if (checkoption.on == YES) {
    NSLog(@"SanityCheck ENABLED");
    sanityCheck = YES;
} else {
    NSLog(@"SanityCheck DISABLED");
    sanityCheck = NO;
}
}

It always returns "SanityCheck DISABLED". The UISwitch checkoption is correcty linked to its object fr开发者_如何学编程om the XIB file and proper @propery and @syntetize setting have been placed.


Replace the code with the this code. and connect again with switch as value change control event.

- (IBAction) sanitySwitch:(id)sender {
    if ([sender isOn]) {
        NSLog(@"SanityCheck ENABLED");
        sanityCheck = YES;
    } 
    else {
        NSLog(@"SanityCheck DISABLED");
        sanityCheck = NO;
    }
}


You are using property "on" wrong way You have to check as follows:

if ([checkoption isOn])

See the documentation properly.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜