Home > Mobile >  How to save selected radiobutton iOS, and in the next time you start the app by default
How to save selected radiobutton iOS, and in the next time you start the app by default

Time:11-23

Have bosses can teach, how to save the selected radiobutton in ios, and in the next time you start the app by default this option is selected to


 
- (void) viewDidLoad {
[super viewDidLoad];
NSUserDefaults * defaults=[NSUserDefaults standardUserDefaults];
Self. RadioButton1. Selected=[defaults boolForKey: @ "radiobutton"].
Self. RadioButton2. Selected=[defaults boolForKey: @ "radiobutton"].
Self. RadioButton3. Selected=[defaults boolForKey: @ "radiobutton"].
[self. RadioButton1 addTarget: self action: @ the selector (RadioButton1) forControlEvents: (UIControlEventValueChanged)];
[the self view addSubview: self RadioButton1];
//Do any additional setup after loading the view.
}


- (IBAction) onRadioBtn: RadioButton *) sender {
_statusLabel. Text=[nsstrings stringWithFormat: @ "% @", sender. TitleLabel. Text];
NSUserDefaults * defaults=[NSUserDefaults standardUserDefaults];
BOOL an isSelected=[[NSUserDefaults standardUserDefaults] boolForKey: @ "radiobutton"].
An isSelected=! An isSelected;
[defaults setBool: sender. Selected forKey: @ "radiobutton"].
[defaults the synchronize];
}

@ end

CodePudding user response:

 
[radioButton setSelected: YES]

CodePudding user response:

See you write so no problem

CodePudding user response:

refer to the second floor after 90 taxpayers' response:
see you write no problem
if it is more than one button is whether need to record is selected, you need to save each button corresponds to a key record
  •  Tags:  
  • iOS
  • Related