views:

38

answers:

2

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 from the XIB file and proper @propery and @syntetize setting have been placed.

A: 

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

if ([checkoption isOn])

See the documentation properly.

Satyam svv
I've tried to use if ([checkoption isOn]), the method still always returns "SanityCheck DISABLED".
Kami
Satyam, `getter=foo` only applies to explicit calls like `[switch isOn]`, not to the dot-syntax.
Georg Fritzsche
+1  A: 

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;
    }
}
K D
To markup code indent by 4 spaces or select the code and press the `010` button - no need for html tag etc.
Georg Fritzsche