//
// ViewController.m
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *userTF;
@property (weak, nonatomic) IBOutlet UITextField *passWordTF;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
//点击登录方法
- (IBAction)login:(id)sender {
//创建NSUserDefaults对象
NSUserDefaults*userDes=[NSUserDefaults standardUserDefaults];
//获取NSUserDefaults的账户
NSString*user=[userDesobjectForKey:@"user"];
NSString*pass=[userDesobjectForKey:@"pass"];
//判断是否成功 如果user,pass和输入框的文字相同 则登录成功 否则失败
if([self.userTF.text isEqualToString:user]&&[self.passWordTF.text isEqualToString:pass]){
//创建提示框
UIAlertView*alertV=[[UIAlertViewalloc]initWithTitle:@"提示框"message:@"登录成功"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
//展示提示框
[alertVshow];
}else{
//创建提示框
UIAlertView*alertV=[[UIAlertViewalloc]initWithTitle:@"提示框"message:@"登录失败"delegate:selfcancelButtonTitle:@"确定"otherButtonTitles:nil,nil];
//展示提示框
[alertVshow];
}
}
//点击注册方法
- (IBAction)zhuCe:(id)sender {
//获取输入框的文字
NSString*userStr =self.userTF.text;
NSString*passStr=self.userTF.text;
//将获取的文字存储到 NSUserDefaults
if(self.userTF.text.length!=0&&self.passWordTF.text.length!=0){
//创建 NSUserDefaults
NSUserDefaults*userDes=[NSUserDefaults standardUserDefaults];
//存储
[userDessetObject:userStrforKey:@"user"];
[userDessetObject:passStrforKey:@"pass"];
}else{
//创建提示框
UIAlertView*alertV=[[UIAlertView alloc]initWithTitle:@"提示框" message:@"用户名或密码不能为空" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil, nil];
//展示提示框
[alertVshow];
}
}
@end