//
// ViewController.m
// iosLogin
//
// Created by 曹晗 on 16/2/25.
// Copyright :emoji: 2016年 CaoHan. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *txtUser;
@property (weak, nonatomic) IBOutlet UITextField *txtPwd;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)LoginClick:(id)sender {
//前后去空格
NSString *userName = [_txtUser.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *userPwd = [_txtPwd.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSDictionary *jsonDic = [self getJsonData:userName userpwd:userPwd];
NSString* loginFlag = [jsonDic objectForKey:@"loginFlag"];
NSLog(@"%@",loginFlag);
[self aletrInfo:loginFlag];
}
- (IBAction)registButton:(id)sender {
UIStoryboard *storboard = self.storyboard;
registViewController *vc2 = [storboard instantiateViewControllerWithIdentifier:@"vc2"];
[self presentViewController:vc2 animated:YES completion:nil];
}
//用于请求PHP 获得JSON
- (NSDictionary *)getJsonData:(NSString *)user_name userpwd:(NSString *)user_pwd {
NSError *error;
NSString *urlString = [NSString stringWithFormat:@"http://192.168.1.106/iosLogin/index.php?action=login&user_name=%@&user_pwd=%@",user_name,user_pwd];
//加载一个NSURL对象
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
//将请求的url数据放到NSData对象中
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"接收到的数据为%@",jsonDic);
return jsonDic;
}
//弹出信息
- (void)aletrInfo:(NSString *)loginFlag{
UIAlertView *alert = [[UIAlertView alloc]init];
[alert setTitle:@"提示"]; [alert setDelegate:nil];
[alert addButtonWithTitle:@"确定"];
if ([loginFlag isEqual: @"0"]) {
[alert setMessage:@"账号或密码错误"];
}
if ([loginFlag isEqual:@"1"]) {
[alert setMessage:@"登陆成功"];
}
[alert show];
}
@end
//
// registViewController.m
// iosLogin
//
// Created by 曹晗 on 16/2/27.
// Copyright 2016年 CaoHan. All rights reserved.
//
#import "registViewController.h"
@interface registViewController ()
@property (weak, nonatomic) IBOutlet UITextField *txtUser;
@property (weak, nonatomic) IBOutlet UITextField *txtPwd;
@end
@implementation registViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//这个是注册按钮
- (IBAction)registButton:(id)sender {
NSString *userName = [_txtUser.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSString *userPwd = [_txtPwd.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSDictionary *jsonDic = [self getJsonData:userName userpwd:userPwd];
NSString* registFlag = [jsonDic objectForKey:@"registFlag"];
NSLog(@"%@",registFlag);
[self aletrInfo:registFlag];
}
//这个是返回按钮
- (IBAction)returnButton:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (NSDictionary *)getJsonData:(NSString *)user_name userpwd:(NSString *)user_pwd {
NSError *error;
NSString *urlString = [NSString stringWithFormat:@"http://192.168.1.106/iosLogin/index.php?action=regist&user_name=%@&user_pwd=%@",user_name,user_pwd];
//加载一个NSURL对象
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
//将请求的url数据放到NSData对象中
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中
NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"接收到的数据为%@",jsonDic);
return jsonDic;
}
- (void)aletrInfo:(NSString *)registFlag{
UIAlertView *alert = [[UIAlertView alloc]init];
[alert setTitle:@"提示"]; [alert setDelegate:nil];
[alert addButtonWithTitle:@"确定"];
if ([registFlag isEqual: @"0"]) {
[alert setMessage:@"用户名已存在"];
}
if ([registFlag isEqual:@"1"]) {
[alert setMessage:@"注册成功"];
}
[alert show];
}
@end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有