标签:
我最近一直都有在看关于IOS项目的知识,今天也总算是迎来了我的第一个IOS项目。不巧这个项目并不是从头开始开发,而是在基础上维护并添加一些模块。
噗~不管怎么样,还是来分析分析一下源码吧~我这里首先看到的是AppDelegate_iPad.m下的didFinishLaunchingWithOptions方法,这个方法顾名思义应该是应用启动加载完成后所执行的一个方法。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //[NSUserDefaults standardUserDefaults] 获取用户的一些配置信息 if([[[NSUserDefaults standardUserDefaults] stringForKey:@"AddresstheText"] length]==0){ [[NSUserDefaults standardUserDefaults] setObject:@"http://xxxx.com" forKey:@"AddresstheText"]; [[NSUserDefaults standardUserDefaults] synchronize]; } [[NSUserDefaults standardUserDefaults] setObject:@"wangmin" forKey:@"userNameValue"]; [[NSUserDefaults standardUserDefaults] setObject:@"1111" forKey:@"useridValue"]; [[NSUserDefaults standardUserDefaults] synchronize]; FFADSViewController * controller = [[[FFADSViewController alloc] init] autorelease]; //initWithRootViewController的参数API是这样说的,大概就是什么controller都可以,但不能是tabbarcontroller //The root view controller that is pushed on the stack with no animation. It cannot be an instance of tab bar controller. UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:controller]; //不要显示navigationcontroller的bar [nav setNavigationBarHidden:YES]; //UIDevice可以获取当前设备信息 if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0){ [self.window addSubview:nav.view]; }else{ self.window.rootViewController = nav; } [self.window makeKeyAndVisible]; return YES; }
接下来稍微的扫一下盲,NSUserDefualts standardUserDefualts是什么呢?
接下来我们来看FFADSViewController~!往下走!GO!
#import "FFADSViewController.h" #import "FFLrcController.h" @implementation FFADSViewController -(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:YES]; [self.navigationController setNavigationBarHidden:YES animated:NO]; } //这个页就相当于app进入login页面之前,需要缓冲一些数据会在这个页面停留1-2秒种 - (void)loadView { [super loadView]; CGRect frame = CGRectMake(0, 0, 768, 1024); UIImage * image = [UIImage imageNamed:@"ipadguodu"]; UIImageView * imageView = [[UIImageView alloc] initWithImage:image]; CGRect imageFrame = frame; imageView.frame = imageFrame; imageView.tag = 100; //addSubview 添加子视图 [self.view addSubview:imageView]; [imageView release]; //延迟2秒钟后执行toController [self performSelector:@selector(toController) withObject:nil afterDelay:2]; } -(void)toController{ FFLrcController *publish = [[FFLrcController alloc]init]; UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:publish]; //presentModalViewController:弹出视图 [self presentModalViewController:nav animated:NO]; [publish release]; } - (void)dealloc { [super dealloc]; } @end
这个controller很简单,继续往下走FFLrcController估计就是登录页面了,真是不容易啊!走了好多路才到了登录界面。登录页面首先执行的是loadView事件
注:remember、login、personnumber、password、state等属性都已经在FFLrcController.h中定义
- (void)loadView { [super loadView];//隐藏导航bar [self.navigationController setNavigationBarHidden:YES animated:NO]; //设置背景颜色 self.view.backgroundColor=[UIColor colorWithRed:235/255.0 green:232/255.0 blue:222/255.0 alpha:1]; //label,设置相应的字体颜色背景等等信息 UILabel *remember=[[UILabel alloc]initWithFrame:CGRectMake(100, 733, 150, 30)]; remember.textColor=[UIColor colorWithRed:189/255.0 green:183/255.0 blue:167/255.0 alpha:1]; remember.text=@"记住登录状态"; [self.view addSubview:remember]; [remember release]; //登陆 login = [[UITextField alloc] initWithFrame:CGRectMake(345, 452, 300, 40)]; login.backgroundColor = [UIColor clearColor]; login.borderStyle = UITextBorderStyleRoundedRect; login.borderStyle=UITextBorderStyleNone; //“委托的意思不就是自己的任务交给其他人去做么” //对象.delegate=self的意思就是对象的任务交给self去做 对象!=self login.delegate = self; login.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) login.placeholder=@"姓名"; login.returnKeyType = UIReturnKeyDone; [self.view addSubview:login]; personnumber = [[UITextField alloc] initWithFrame:CGRectMake(345, 545, 300, 40)]; personnumber.backgroundColor = [UIColor clearColor]; personnumber.borderStyle = UITextBorderStyleRoundedRect; personnumber.borderStyle=UITextBorderStyleNone; personnumber.delegate = self; personnumber.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) personnumber.placeholder=@"身份证号码"; personnumber.returnKeyType = UIReturnKeyDone; [self.view addSubview:personnumber]; //密码 password = [[UITextField alloc] initWithFrame:CGRectMake(345, 636, 300, 40)]; password.secureTextEntry=YES; password.backgroundColor = [UIColor clearColor]; password.borderStyle = UITextBorderStyleRoundedRect; password.delegate = self; password.borderStyle=UITextBorderStyleNone; password.keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) password.placeholder=@"密码"; password.returnKeyType = UIReturnKeyDone; [self.view addSubview:password];//记住状态 state = [UIButton buttonWithType:UIButtonTypeCustom]; state.frame =CGRectMake(50, 720, 52, 52); //UIControlEventTouchDown事件后会转跳到remember方法中做处理 [state addTarget:self action:@selector(remember) forControlEvents:UIControlEventTouchDown]; [state setBackgroundImage:[UIImage imageNamed:@"ipadcheckLogin"] forState:UIControlStateNormal]; [self.view addSubview:state]; //登陆按钮 UIButton *check = [UIButton buttonWithType:UIButtonTypeCustom]; check.frame =CGRectMake(350, 725, 319, 72); [check.titleLabel setFont:[UIFont boldSystemFontOfSize:18]]; //UIControlEventTouchDown事件后会执行goHome [check addTarget:self action:@selector(goHome) forControlEvents:UIControlEventTouchDown]; [check setBackgroundImage:[UIImage imageNamed:@"ipadlogin_btn"] forState:UIControlStateNormal]; [self.view addSubview:check]; //他这里condition方法编写的是假如有记住密码则将配置文件里的信息读取到UITextField当中 [self condition]; }
FFLrcController.h ---> goHome事件
- (void)goHome { //交出第一响应的身份,可能是回收键盘操作 [login resignFirstResponder]; [personnumber resignFirstResponder]; [password resignFirstResponder]; //SVProgressHUD 是一个第三方的控件,是一个弹出提示层,用来提示网络加载或提示对错 [SVProgressHUD showWithStatus:@"数据加载中..." maskType:SVProgressHUDMaskTypeClear]; //不重复,只调用一次。timer运行一次就会自动停止运行 timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(loginTO) userInfo:nil repeats:NO]; }
FFLrcController.h ---> loginTO事件
-(void)loginTO{ //设置URL 这里相当于 http://xxxx.com/CheckLogin/index/type/name/001/IDcardNO/331004xxxxxxxx/password/001/uuid/e1e2ed3sgfw2/macaddress/192.168.1.1/checkword/?p=ui
//总之这个根据服务器具体所需要的url来配置 NSString *urlString=[NSString stringWithFormat:@"%@/CheckLogin/index/type//name/%@/IDcardNO/%@/password/%@/uuid/%@/macaddress/%@/checkword/?p=ui"
,@"http://xxxx.com",login.text,personnumber.text,password.text,[self getUUID],[self getMacAddress]]; //NSLog(@"urlString %@",urlString); NSURL *url=[NSURL URLWithString:urlString]; //ASIHTTPRequest类库中的ASIFormDataRequest是实现HTTP协议中的处理POST表单的很好的类库。 ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url]; [request setDelegate:self]; //成功后调用dataFetchComplete [request setDidFinishSelector:@selector(dataFetchComplete:)]; //失败后调用dataFail [request setDidFailSelector:@selector(dataFail:)]; [request setTimeOutSeconds:60]; [[SEAOperationQueue mainQueue] addOperation:request]; [request release]; }
FFLrcController.h ---> dataFetchComplete事件
- (void)dataFetchComplete:(ASIHTTPRequest *)request { //隐藏进度条框 [SVProgressHUD dismiss]; //从服务器中得到的数据是二进制的 NSData * data = [request responseData]; if (data) {//从服务器得到返回的数据转UTF-8,这里为什么不是json,竟然带有html的 NSString *myString = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding]; //这里过滤掉一些标签如:<script></script>等 //使用NSString的stringByReplacingOccurrencesOfString:@"要过滤的" withString:@"替换成的"方法 //以下省略9行过滤代码if ([myString isEqualToString:@"您的身份证号码有误!"]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"身份证号码输入错误" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil, nil]; [alert show]; [alert release]; return; }else if ([myString isEqualToString:@"用户名或密码输入错误!"]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"登陆信息输入错误" delegate:nil cancelButtonTitle:@"确认" otherButtonTitles:nil, nil]; [alert show]; [alert release]; return; }else if ([myString hasPrefix:@"/userid"]) { myString=[myString stringByReplacingOccurrencesOfString:@"/userid/" withString:@""]; if (flag) { [[NSUserDefaults standardUserDefaults] setObject:@"true" forKey:@"flag"]; [self writeUser]; }else{ [[NSUserDefaults standardUserDefaults] setObject:@"false" forKey:@"flag"]; } //记录登陆时间写入配置文件 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"YYYY-MM-dd"]; NSString *timestamp = [formatter stringFromDate:[NSDate date]]; NSString *countTime=@"上次登陆:"; countTime=[countTime stringByAppendingString:timestamp]; [[NSUserDefaults standardUserDefaults] setObject:countTime forKey:@"loginTime"]; [formatter release]; //这里登陆成功后,写入一些信息到配置文件。这里省去一些代码 FFFFSwitchViewController *controller = [[FFFFSwitchViewController alloc]init]; controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self.navigationController pushViewController:controller animated:YES]; [controller release]; } } }
可以看到接下来就是FFFFSwitchViewController
----明天继续写
标签:
原文地址:http://www.cnblogs.com/chenjianxiang/p/4442859.html