//注册页面的Button事件
- (IBAction)action:(id)sender {
if ([self.username.text isEqualToString:@""]||[self.password.text isEqualToString:@""]||[self.Apassword.text isEqualToString:@""])
{
UIAlertView *av=[[UIAlertView alloc] initWithTitle:@"提示" message:@"输入不能为空" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[av show];
}
else
{
if (![self.password.text isEqualToString:self.Apassword.text]) {
UIAlertView *av=[[UIAlertView alloc] initWithTitle:@"提示" message:@"输入密码不一致" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[av show];
}else
{
//NSUserDefaults 存一些短小数据
//在注册里将账号密码存入进去,去登录里取出数据
NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
[user setObject:self.username.text forKey:@"userName"];
[user setObject:self.Apassword.text forKey:@"passWord"];
[user synchronize];
[self dismissViewControllerAnimated:YES completion:nil];
}
}
}
****************************
//登录
- (IBAction)landing:(id)sender {
//NSUserDefaults 存放在Library文件perferences中
NSUserDefaults *user=[NSUserDefaults standardUserDefaults];
if ([[user objectForKey:@"userName"]isEqualToString:self.userName.text]&&[[user objectForKey:@"passWord"]isEqualToString:self.passWord.text]) {
UIAlertView *av=[[UIAlertView alloc] initWithTitle:@"提示" message:@"登陆成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[av show];
}
else
{
UIAlertView *av=[[UIAlertView alloc] initWithTitle:@"提示" message:@"登陆失败" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
[av show];
}
}