BOOL isSaveInfo;
- (void)viewDidLoad {
[super viewDidLoad];
[self initSave];
}
-(void)initSave
{
NSUserDefaults *df = [NSUserDefaults standardUserDefaults];
if ([[df objectForKey:@"isSave"] isEqualToString:@"YES"])
{
isSaveInfo = true;
}
else
{
isSaveInfo = false;
}
NSString *thePassword = [df valueForKey:@"password"];
NSString *user = [df valueForKey:@"userName"];
if (isSaveInfo && thePassword)
{
self.userName.text = user;
self.password.text=thePassword;
}
else
{
self.password.text = nil;
}
NSString * imageStr = isSaveInfo == true ? @"勾选框选中":@"勾选框";
self.rememberImg.image = [UIImage imageNamed:imageStr];
}
- (IBAction)RememberPassWord:(id)sender {
NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
[user removeObjectForKey:@"isSave"];
if (isSaveInfo == true)
{
isSaveInfo = false;
self.rememberImg.image = [UIImage imageNamed:@"勾选框"];
[user setObject:@"NO" forKey:@"isSave"];
}
else
{
isSaveInfo = true;
self.rememberImg.image = [UIImage imageNamed:@"勾选框选中"];
[user setObject:@"YES" forKey:@"isSave"];
}
[user synchronize];
}