mercredi 2 novembre 2016

objective c store checkbox selection and view selection in another view

I have 4 checkboxes, where there are 4 images attached, that I like to store by clicking the save button, and when i open my secondViewController, i like to see see the checked images.

This is my code so fare

- (IBAction)checkboxButton:(id)sender{

    if ([sender isSelected]) {
        [sender setSelected:NO];
        [sender setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateSelected];
        [[NSUserDefaults standardUserDefaults] setBool:FALSE forKey:@"selected"];
        return;
    }
    if([sender tag] == 0){
        [sender setSelected:YES];
        [sender setImage:[UIImage imageNamed:@"checkbox-checked.png"] forState:UIControlStateSelected];
        [[NSUserDefaults standardUserDefaults]setObject:[NSNumber numberWithBool:YES] forKey:@"REMEMBER_ME"];
    }
    if ([sender tag] == 1) {
        [sender setSelected:YES];
        [sender setImage:[UIImage imageNamed:@"checkbox-checked.png"] forState:UIControlStateSelected];
        [[NSUserDefaults standardUserDefaults]setObject:[NSNumber numberWithBool:YES] forKey:@"REMEMBER_ME"];
    }
    if ([sender tag] == 2) {
        [sender setSelected:YES];
        [sender setImage:[UIImage imageNamed:@"checkbox-checked.png"] forState:UIControlStateSelected];
        [[NSUserDefaults standardUserDefaults]setObject:[NSNumber numberWithBool:YES] forKey:@"REMEMBER_ME"];
    }
    if ([sender tag] == 3) {
        [sender setSelected:YES];
        [sender setImage:[UIImage imageNamed:@"checkbox-checked.png"] forState:UIControlStateSelected];
        [[NSUserDefaults standardUserDefaults]setObject:[NSNumber numberWithBool:YES] forKey:@"REMEMBER_ME"];
    }

    [[NSUserDefaults standardUserDefaults] synchronize];
}

- (IBAction)btnSaveselected:(id)sender{


}

- (void)viewDidLoad {
    checkboxSelected = 0;
    [super viewDidLoad];

}

Can you please help my with 2 things

How to save the selected checkboxes by clicking the button save, and how to show the selected checkboxes in my second view?




Aucun commentaire:

Enregistrer un commentaire