lundi 10 mai 2021

How to enable an UISwitch while disabling other two simultaneously

I have 3 UISwitches in my View Controller and each one identifies gender ("Woman, Male, No Gender") that user has to choose.

The behavior I would like to implement is that, when the user taps on a switch to select the gender, the others two have to be disabled simultaneously. And once the switch is selected, the "Create Profile" button is activated. (screenshots attached)

I'm not able to implement the if condition (or alternatively a switch condition)to do that. Please help.

This is the code I implemented:

- (IBAction)checkGenderSwitch:(id)sender {
if ([self.femaleGenderSwitch isOn] && (![self.maleGenderSwitch isOn] && ![self.noGenderSwitch isOn])) {
    [self enableCreateProfileButton];
} else if ([self.maleGenderSwitch isOn] && (![self.femaleGenderSwitch isOn] && ![self.noGenderSwitch isOn])) {
    [self enableCreateProfileButton];
} else if ([self.noGenderSwitch isOn] && (![self.femaleGenderSwitch isOn] && ![self.maleGenderSwitch isOn])) {
    [self enableCreateProfileButton];
}else{
    [self disableCreateProfileButton];
    }

}

Thanks.

Aucun commentaire:

Enregistrer un commentaire