- 源代码下载链接:05-偏好设置.zip
35.9 KB
- //
- // MJViewController.m
- // 03-Plist属性列表
- //
- // Created by apple on 13-12-11.
- // Copyright (c) 2013年 itcast. All rights reserved.
- //
- #import "MJViewController.h"
- @interface MJViewController ()
- @end
- /*
- normal 默认就是
- highlighted 长按
- disable enabled = NO
- selected selected = YES
- */
- @implementation MJViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
-
- _qqField.text = [user objectForKey:@"qq"];
- _rmbPwdBtn.selected = [user boolForKey:@"rmb_pwd"];
- _autoLoginBtn.selected = [user boolForKey:@"auto_login"];
-
- if (_rmbPwdBtn.selected) {
- _pwdField.text = [user objectForKey:@"pwd"];
- }
- }
- #pragma mark 记住密码
- - (IBAction)rmbPwd:(UIButton *)sender {
- sender.selected = !sender.selected;
- //本文永久链接,转载请注明出处:http://www.cnblogs.com/ChenYilong/p/3490634.html
- if (sender.selected == NO) { // 取消勾选了记住密码
- // 取消勾选”自动登录“
- _autoLoginBtn.selected = NO;
- }
- }
- #pragma mark 自动登录
- - (IBAction)autoLogin:(UIButton *)sender {
- sender.selected = !sender.selected;
-
- if (sender.selected) { // 勾选了自动登录
- // 勾选“记住密码”
- _rmbPwdBtn.selected = YES;
- }
- }
- - (IBAction)login {
- // 1.存储数据
- NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
- //本文永久链接,转载请注明出处:http://www.cnblogs.com/ChenYilong/p/3490634.html
- [user setObject:_qqField.text forKey:@"qq"];
- // if (_rmbPwdBtn.selected) {
- [user setObject:_pwdField.text forKey:@"pwd"];
- // }
- [user setBool:_rmbPwdBtn.selected forKey:@"rmb_pwd"];
- [user setBool:_autoLoginBtn.selected forKey:@"auto_login"];
-
- // 2.马上进行存储(马上进行同步)
- [user synchronize];
- }
- @end
https://www.evernote.com/shard/s227/sh/e5e41cd8-c8f0-4ea3-879d-2e15e4455a34/a9c67901bfd3192ddb1ab158787fa4b9