首页 > 代码库 > 代码运行顺序(部分)

代码运行顺序(部分)

///////当应用程序接在完成时触发
- (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.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
     view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    view.backgroundColor = [UIColor greenColor];
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(60, 100, 200, 40)];
    label.text = @"text";
    label.backgroundColor = [UIColor whiteColor];
    [view addSubview:label];
    [label release];
    
    
    UIButton * button  =[UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor whiteColor];
    button.frame = CGRectMake(60, 300, 200, 40);
    [button setTitle:@"按钮" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(sel:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    
    
    
    UITextField * field = [[UITextField alloc]initWithFrame:CGRectMake(60, 200, 200, 40)];
    field.tag =100;
    field.delegate =self;
    field.keyboardType = UIKeyboardTypeNumberPad;
    field.clearButtonMode = UITextFieldViewModeAlways;
    field.text = @"dfglsdfgsd";
    field.backgroundColor  =[UIColor whiteColor];
    [view addSubview:field];
    [field release];
    
  //  SEL selector = NSSelectorFromString(@"click"); // 将字符串转化为方法名
    
    [self.window addSubview:view];
    [view release];
    return YES;
}

//点击按钮时,判断输入框中中的文字是否是十一位,不过不是提示给用户.
- (void)sel:(UIButton *)button
{
    //获取输入框
    UITextField * TF = (UITextField *)[self.window viewWithTag:100];
    
    //2.判断输入框文字的长度
    if ([TF.text length] != 11) {
        NSLog(@"手机号码输入错误");
        
        //提示控件----
        
        //Title : 标题
        //message : 提示消息
        //delegate  : 代理
        //cancelButtonTitle : 取消显示
        //otherButtonTitles : 其他按钮显示文字,只给出按钮显示的文字即可,可多个
        UIAlertView * alertView =  [[UIAlertView alloc]initWithTitle:@"警告"
                                                             message:@"手机号码输入错误"
                                                            delegate:self
                                                   cancelButtonTitle:@"取消"
                                                   otherButtonTitles:@"确定",@"sure", nil];
        //// UIAlertViewStyleDefault = 0,            默认
       //// UIAlertViewStyleSecureTextInput,         密码
        ////UIAlertViewStylePlainTextInput,          输入框
       //// UIAlertViewStyleLoginAndPasswordInput       登录,密码

        
        alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
        
        [alertView show]; //让alertView 弹出
        
        [alertView release];
    }

    
    
    [TF resignFirstResponder];
}





//当点击button时 触发的方法.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //取消按钮的buttonindex 为 0
    //其他的按钮从左往右依次 + 1 ;
    NSLog(@"%d",buttonIndex);
    
    //通过switch..case 匹配是哪一个按钮按下
    switch (buttonIndex) {
        case 0:
            NSLog(@"取消");
            break;
        case 1:
            NSLog(@"确定");
            break;
        case 2:
            NSLog(@"sure");
            break;
        default:
            break;
    }
}

//当我们取消一个视图(如。用户单击按钮)。这不是用户单击取消按钮时调用。
//如果没有定义的委托,我们模拟点击取消按钮
//- (void)alertViewCancel:(UIAlertView *)alertView;

//- (void)willPresentAlertView:(UIAlertView *)alertView;    / /动画和之前显示视图
//- (void)didPresentAlertView:(UIAlertView *)alertView;  / /动画后

//- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;    / /之前动画和隐藏视图
//- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  / /动画后


//- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;/ /编辑的任何违约后称为字段添加的风格










//询问当前编辑框能否被编辑  YES 能 NO 不能
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}

//当编辑框开始编辑时触发(获得焦点后触发)
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
}

//询问当前输入框是否可以结束编辑(键盘是否可以收回)
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}

//当前输入框结束编辑时触发(键盘收回后触发).
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
}

//当输入框文字发生变化时就会触发. (只有通过键盘输入时文字改变,触发)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}


//用来控制输入框的清除按钮是否具有清除功能. YES 有 NO 没有
- (BOOL)textFieldShouldClear:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}


//当点击键盘右下角的return按钮时触发
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    NSLog(@"%s",__FUNCTION__);
    return YES;
}





//当有电话进入时
//1.  应用程序状态:  applicationWillResignActive:
//(第一种情况)拒绝
//     2. 应用程序状态: applicationDidBecomeActive:

//(第二种情况)接听电话
//      2. 应用程序状态: applicationDidEnterBackground ;






///////当运用程序取消活跃状态时(将要进入后台挂起时触发)
- (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
{
    
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}




//
//  AppDelegate.m
//  LessonComprehensive
//
//  Created by lanouhn on 14-8-21.
//  Copyright (c) 2014年 李前成. All rights reserved.
//

#import "TestDelegate.h"

@interface TestDelegate ()
{
    UIView * view;
}
@end
@implementation TestDelegate
- (void)dealloc
{
    [_window release];
    [super dealloc];
}




///////当应用程序接在完成时触发
- (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.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
    view.backgroundColor = [UIColor greenColor];
    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(60, 100, 200, 40)];
    label.text = @"text";
    label.backgroundColor = [UIColor whiteColor];
    [view addSubview:label];
    [label release];
    
    
    UIButton * button  =[UIButton buttonWithType:UIButtonTypeSystem];
    button.backgroundColor = [UIColor whiteColor];
    button.frame = CGRectMake(60, 300, 200, 40);
    [button setTitle:@"按钮" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(sel:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    
    
    
    UITextField * field = [[UITextField alloc]initWithFrame:CGRectMake(60, 200, 200, 40)];
    field.tag =100;
    field.delegate =self;
    field.keyboardType = UIKeyboardTypeNumberPad;
    field.clearButtonMode = UITextFieldViewModeAlways;
    field.text = @"dfglsdfgsd";
    field.backgroundColor  =[UIColor whiteColor];
    [view addSubview:field];
    [field release];
    
    //  SEL selector = NSSelectorFromString(@"click"); // 将字符串转化为方法名
    
    [self.window addSubview:view];
    [view release];
    return YES;
}

//点击按钮时,判断输入框中中的文字是否是十一位,不过不是提示给用户.
- (void)sel:(UIButton *)button
{
    //获取输入框
    UITextField * TF = (UITextField *)[self.window viewWithTag:100];
    
    //2.判断输入框文字的长度
    if ([TF.text length] != 11) {
        NSLog(@"手机号码输入错误");
        
        //提示控件----
        
        //Title : 标题
        //message : 提示消息
        //delegate  : 代理
        //cancelButtonTitle : 取消显示
        //otherButtonTitles : 其他按钮显示文字,只给出按钮显示的文字即可,可多个
        UIAlertView * alertView =  [[UIAlertView alloc]initWithTitle:@"警告"
                                                             message:@"手机号码输入错误"
                                                            delegate:self
                                                   cancelButtonTitle:@"取消"
                                                   otherButtonTitles:@"确定",@"sure", nil];
        //// UIAlertViewStyleDefault = 0,            默认
        //// UIAlertViewStyleSecureTextInput,         密码
        ////UIAlertViewStylePlainTextInput,          输入框
        //// UIAlertViewStyleLoginAndPasswordInput       登录,密码
        
        
        alertView.alertViewStyle = UIAlertViewStyleSecureTextInput;
        
        [alertView show]; //让alertView 弹出
        
        [alertView release];
    }
    
    
    
    [TF resignFirstResponder];
}





//当点击button时 触发的方法.
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    //取消按钮的buttonindex 为 0
    //其他的按钮从左往右依次 + 1 ;
    NSLog(@"%d",buttonIndex);
    
    //通过switch..case 匹配是哪一个按钮按下
    switch (buttonIndex) {
        case 0:
            NSLog(@"取消");
            break;
        case 1:
            NSLog(@"确定");
            break;
        case 2:
            NSLog(@"sure");
            break;
        default:
            break;
    }
}

//当我们取消一个视图(如。用户单击按钮)。这不是用户单击取消按钮时调用。
//如果没有定义的委托,我们模拟点击取消按钮
//- (void)alertViewCancel:(UIAlertView *)alertView;

//- (void)willPresentAlertView:(UIAlertView *)alertView;    / /动画和之前显示视图
//- (void)didPresentAlertView:(UIAlertView *)alertView;  / /动画后

//- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;    / /之前动画和隐藏视图
//- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;  / /动画后


//- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;/ /编辑的任何违约后称为字段添加的风格










//询问当前编辑框能否被编辑  YES 能 NO 不能
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}

//当编辑框开始编辑时触发(获得焦点后触发)
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
}

//询问当前输入框是否可以结束编辑(键盘是否可以收回)
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}

//当前输入框结束编辑时触发(键盘收回后触发).
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
}

//当输入框文字发生变化时就会触发. (只有通过键盘输入时文字改变,触发)
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}


//用来控制输入框的清除按钮是否具有清除功能. YES 有 NO 没有
- (BOOL)textFieldShouldClear:(UITextField *)textField
{
    NSLog(@"%s",__FUNCTION__);
    return YES;
}


//当点击键盘右下角的return按钮时触发
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    NSLog(@"%s",__FUNCTION__);
    return YES;
}





//当有电话进入时
//1.  应用程序状态:  applicationWillResignActive:
//(第一种情况)拒绝
//     2. 应用程序状态: applicationDidBecomeActive:

//(第二种情况)接听电话
//      2. 应用程序状态: applicationDidEnterBackground ;






///////当运用程序取消活跃状态时(将要进入后台挂起时触发)
- (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
{
    
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end

代码运行顺序(部分)