I have a UISwitch object in my .xib file. Its state is On by default. If the user switches it to Off, I want to ask if he’s sure, and if he clicks No – automatically switch it back to On.
So I set these outlet and action in my .h file:
@property (weak, nonatomic) IBOutlet UISwitch *campaignSwitch;
- (IBAction)checkCampaignSwitch:(id)sender;
This is the checkCampaignSwitch method:
- (IBAction)checkCampaignSwitch:(id)sender {
if(self.campaignSwitch.isOn==FALSE)
{
[self allertMessage:@"Receive updates" :@"Are you sure you don't want
to receive updates?" :@"No" :@"Yes"];
}
}
This calls for method to display an Alert message with various parameters (title, text, cancel button and other button).
I also registered for UIAlertViewDelegate and in my .m file I’m trying to implement the clickedButtonAtIndex method like this:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case 0:
[self.campaignSwitch setOn:TRUE];
break;
default:
break;
}
}
I’m getting the Alert message, but nothing happens when I click the No button. Nor the Yes.
So how do I switch it back On?
Had to make sure the UIAlertView is delegated: