iOS程序执行过程
2014-08-21 19:16
253 查看
//UIApplication main函数是应用程序的入口, 做了: //1 创建应用程序对象(UIApplication对象) //2 指定应用程序的代理(通过代理来监测应用程序的执行状态) //3 创建事件循环(死循环) // // CCLAppDelegate.m // LessonComprehensive // // Created by lanouhn on 14-8-21. // Copyright (c) 2014年 vaercly@163.com 陈聪雷. All rights reserved. // #import "CCLTestDelegte.h" @interface CCLTestDelegte () { UIView *_bgView; UILabel *_lable; UITextField *_tf; UIButton *_button; } @end @implementation CCLTestDelegte //当应用程序加载完成之时触发 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSLog(@"%s", __FUNCTION__); self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. _bgView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 568)]; _bgView.backgroundColor = [UIColor whiteColor]; [self.window addSubview:_bgView]; [_bgView release]; _lable = [[UILabel alloc] initWithFrame:CGRectMake(110, 50, 100, 40)]; _lable.backgroundColor = [UIColor grayColor]; _lable.layer.cornerRadius = 5; _lable.text = @"lable"; _lable.layer.masksToBounds = YES; [_bgView addSubview:_lable]; [_lable release]; _tf = [[UITextField alloc] initWithFrame:CGRectMake(110, 110, 100, 40)]; _tf.backgroundColor = [UIColor grayColor]; _tf.placeholder = @"文本框"; _tf.keyboardType = UIKeyboardTypeNumberPad; _tf.clearButtonMode = UITextFieldViewModeWhileEditing; _tf.delegate = self; _tf.tag = 100; _tf.layer.cornerRadius = 5; [_bgView addSubview:_tf]; [_tf release]; _button = [UIButton buttonWithType:UIButtonTypeSystem]; _button.frame = CGRectMake(110, 170, 100, 40); [_button setTitle:@"点我" forState:UIControlStateNormal]; [_button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]; _button.layer.cornerRadius = 5; _button.layer.masksToBounds = YES; _button.backgroundColor = [UIColor grayColor]; [_bgView addSubview:_button]; // SEL sel = NSSelectorFromString(@"click:");将方法名字符串转换为方法 self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; return YES; } //点击按钮判断输入框中的文字是否是11位, 若不是11为则提示用户输入错误 - (void)click:(UIButton *)button { //1 获取输入框 UITextField *tf = (UITextField *)[button.superview viewWithTag:100]; //2 判断输入框文字的长度 if ([tf.text length] != 11) { // NSLog(@"手机号码输入错误"); //title 提示框的标题 message 提示框的提示信息 delegate 代理 cancelButtonTitle 取消按钮显示的文字 otherButtonTitles 其他按钮显示的文字, 只给按钮显示的文字即可, 可以有多个 UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"手机号输入有误" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"啊", @"确定", nil]; //让alert弹出 //UIAlertViewStyleDefault = 0, //UIAlertViewStyleSecureTextInput, //UIAlertViewStylePlainTextInput, //UIAlertViewStyleLoginAndPasswordInput alertView.alertViewStyle = UIAlertViewStyleSecureTextInput; [alertView show]; [alertView release]; } } //当点击Button时会触发的方法 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { //取消按钮的buttonIndex为0, 其他的按钮, 从上到下依次加1 NSLog(@"buttonIndex %d", buttonIndex); //通过switch case来判断哪个按钮被点击 switch (buttonIndex) { case 0: NSLog(@"取消按钮被点击"); break; case 1: NSLog(@"啊按钮被点击"); break; case 2: NSLog(@"确定按钮被点击"); break; default: break; } } //询问当前输入框能否开始编辑, yes能 no不能 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { //输出方法名 NSLog(@"%s", __FUNCTION__); return YES; }// return NO to disallow editing. //当输入框开始编辑时触发(获得焦点后触发) - (void)textFieldDidBeginEditing:(UITextField *)textField { NSLog(@"%s", __FUNCTION__); }// became first responder //询问当前输入框是否结束编辑(键盘是否收回) - (BOOL)textFieldShouldEndEditing:(UITextField *)textField { NSLog(@"%s", __FUNCTION__); return YES; }// return YES to allow editing to stop and to resign first responder status. NO to disallow the editing session to end //当前输入框结束时触发(键盘收回之后触发) - (void)textFieldDidEndEditing:(UITextField *)textField { NSLog(@"%s", __FUNCTION__); }// may be called if forced even if shouldEndEditing returns NO (e.g. view removed from window) or endEditing:YES called //当前输入框文字发生变化时触发(只有通过键盘输入时, 文字改变, 触发) - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { if (textField.text.length >= 11) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"手机号为11位" delegate:self cancelButtonTitle:@"知道了" otherButtonTitles:@"好", nil]; [alertView show]; alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; [alertView release]; textField.text = [textField.text substringToIndex:10]; } NSLog(@"%s", __FUNCTION__); return YES; }// return NO to not change text //用来控制输入框的清除按钮是否具有清除功能(yes 有 no 没有) - (BOOL)textFieldShouldClear:(UITextField *)textField { NSLog(@"%s", __FUNCTION__); return YES; }// called when clear button pressed. return NO to ignore (no notifications) //当点击键盘右下角的return时触发 - (BOOL)textFieldShouldReturn:(UITextField *)textField { NSLog(@"%s", __FUNCTION__); [textField resignFirstResponder]; return YES; }// called when 'return' key pressed. return NO to ignore. //当应用程序将要取消活跃状态(将要进入后台是触发) - (void)applicationWillResignActive:(UIApplication *)application { NSLog(@"%s", __FUNCTION__); // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } //当应用程序已经进入后台(应用程序被挂起) - (void)applicationDidEnterBackground:(UIApplication *)application { NSLog(@"%s", __FUNCTION__); // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } //当应用将要进入前台是触发(程序将要成为活跃状态) - (void)applicationWillEnterForeground:(UIApplication *)application { NSLog(@"%s", __FUNCTION__); // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } //当应用程序已经成为活跃状态(已经进入前台时触发程序) - (void)applicationDidBecomeActive:(UIApplication *)application { NSLog(@"%s", __FUNCTION__); // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - (void)applicationWillTerminate:(UIApplication *)application { NSLog(@"%s", __FUNCTION__); // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } //当有电话进入时: applicationWillResignActive: 1 拒绝: 应用程序状态: applicationDidBecomeActive: 2 接听:applicationDidEnterBackground: - (void)dealloc { [_window release]; [super dealloc]; } @end
相关文章推荐
- ios_oc 程序执行过程概述
- 李洪强漫谈iOS开发[C语言-002]-开发概述程序的本质与简单执行过程
- PLC执行程序的过程及特点
- Linux操作系统中/sbin/init程序的执行过程
- Linux操作系统中/sbin/init程序的执行过程
- VC++中的MFC程序的执行过程
- 程序执行过程
- WEB程序的执行过程!
- Linux操作系统中/sbin/init程序的执行过程
- 《.NET框架程序设计》读书笔记一--.NET程序的生成以及执行过程
- C程序编译执行过程
- 程序的执行过程
- VC++中的MFC程序的执行过程
- C程序到可执行程序的转换过程
- python程序的执行过程
- 程序执行过程的跟踪:(用debug来跟踪一个程序的运行过程) 整理总结
- C#程序调用Delphi可执行EXE文件过程
- 【编程基础】程序的执行过程
- 在VC++程序中显示存储过程的执行进度
- wxWidgets程序一般执行过程