标签:
//页面一出现则获取NSUserDefaults里面rememberSate的状态来改变UI
-(void)viewWillAppear:(BOOL)animated{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *rememberSate = [userDefaults objectForKey:@"rememberSate"];
if ([rememberSate isEqualToString:@"1"]) {
_rememberBtn.selected = YES;
_usernameTextField.text = [userDefaults objectForKey:@"user_name"];
_passwordTextField.text = [userDefaults objectForKey:@"user_password"];
//记住密码图片显示打勾
[_rememberBtn setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
}else{
_passwordTextField.text = nil;
_usernameTextField.text = nil;
//记住密码图片显示不打勾
[_rememberBtn setImage:[UIImage imageNamed:@"no_check"] forState:UIControlStateNormal];
}
}
//记住密码的点击事件
-(void)btnClick{
//如果选中再点击则不选中
_rememberBtn.selected = !_rememberBtn.selected;
//初始化偏好设置
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if (_rememberBtn.selected) {
DDLogInfo(@"记住密码");
[_rememberBtn setImage:[UIImage imageNamed:@"check"] forState:UIControlStateNormal];
//如果选中,则存入rememberSate的状态为“1”
[userDefaults setObject:@"1" forKey:@"rememberSate"];
[userDefaults synchronize];
}else{
DDLogInfo(@"取消记住密码");
[_rememberBtn setImage:[UIImage imageNamed:@"no_check"] forState:UIControlStateNormal];
[userDefaults setObject:@"0" forKey:@"rememberSate"];
[userDefaults synchronize];
}
}
//在登陆事件
-(void)loginBtn:(UIButton *)sender{
//登陆成功时
// 存储密码和用户名
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:pwd forKey:@"user_password"];
[userDefaults setObject:userName forKey:@"user_name"];
[userDefaults synchronize];
}
标签:
原文地址:http://www.cnblogs.com/dcy123/p/5264344.html