Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 632
Kami Avatar asked Dec 13 '22 19:12

Kami


1 Answers

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;
    }
}
like image 156
deoKasuhal Avatar answered Dec 31 '22 23:12

deoKasuhal