-2

我想这样做:当您按下按钮时,它会更改图像(它是活动的),数据被写入数据库。下次加载按钮时,是否将此按钮设置为活动状态?

4

1 回答 1

2

NSUserDefaults *rememberDefault = [NSUserDefaults standardUserDefaults];

if ([[rememberDefault valueForKey:@"Autologin"] isEqualToString:@"Autologin_on"]) {
    btnAutoLogin.selected =NO;
}else {        
    btnAutoLogin.selected =YES;
}

在您的按钮操作方法中:

-(IBAction)btnOnOffSwitch:(UIButton *)sender{

if (sender.selected) {
    sender.selected = NO;
}else {        
    sender.selected = YES;
}

}

当你想检查使用这个:

NSUserDefaults *rememberDefault = [NSUserDefaults standardUserDefaults];

if([[rememberDefault valueForKey:@"Autologin"] isEqualToString:@"Autologin_on"]){ [self Login_pressed:@""]; }

于 2012-10-12T07:20:21.457 回答