문제

I have a function that checks to see if the UISwitch in the parameter is switched on, if it is, then it will return true. I have an if statement that checks if the function returns true, if it is in fact true, it should nslog, but it doesnt. Any ideas on why when I press the switch it doesnt run? Here's what i'm doing:

-(BOOL)switched:(UISwitch *)currentSwitch{
    return NO;
    if([currentSwitch isOn]){
        return YES;
    }
}

viewWillDisappear{
    if([self switched:campSwitch] == YES){
        NSLog(@"THE FUNCTION RETURNED TRUE");
    }
}
도움이 되었습니까?

해결책

Change your code to the following:

-(BOOL)switched:(UISwitch *)currentSwitch{
    return [currentSwitch isOn];
}

다른 팁

-(BOOL)switched:(UISwitch *)currentSwitch{
    return [currentSwitch isOn];
}

-(void)viewWillDisappear:(BOOL)animated{
    if([self switched:mySwitch]){
        [self saveToCoreData];
        NSLog(@"mySwitch was on.");
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top