我对单选按钮有一些疑问,我希望保留所选的单选按钮,当我再次打开该视图时,我选择的单选按钮应保持选中状态。
-(void)viewDidAppear:(BOOL)animated {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([[defaults valueForKey:@"mobileNumber"] length]>0){
MobileNum.text=[defaults valueForKey:@"mobileNumber"];
}
else {
MobileNum.text=@"";
}
if ([[defaults valueForKey:@"amount"] length]>0) {
amount.text=[defaults valueForKey:@"amount"];
}
else {
amount.text=@"";
}
if ([[defaults valueForKey:@"operator"] length]>0) {
operatorLabel.text = [defaults valueForKey:@"operator"];
}else{
operatorLabel.text = @"Select Operator";
}
if ([[defaults valueForKey:@"circle"] length]>0) {
circleLabel.text = [defaults valueForKey:@"circle"];
}else{
circleLabel.text = @"Select Circle";
}
if ([defaults valueForKey:@"credit card"]) {
[criditRadio setSelected:YES];
}else{
[criditRadio setSelected:NO];
}
if ([defaults valueForKey:@"debit card"]) {
debitRadio.selected=YES;
}else{
debitRadio.selected=NO;
}
if ([defaults valueForKey:@"net bank"]) {
netRadio.selected=NO;
}
}
答案 0 :(得分:0)
你的编码很好
if ([defaults valueForKey:@"credit card"]) {
[criditRadio setSelected:YES];
}else{
[criditRadio setSelected:NO];
}
if ([defaults valueForKey:@"debit card"]) {
debitRadio.selected=YES;
}else{
debitRadio.selected=NO;
}
if ([defaults valueForKey:@"net bank"]) {
netRadio.selected=NO;
}
这里你需要每次比较NSUserdefault Value
以浏览此页面
在这里,我根据您的需要附加了示例项目,下载了project