代码运行顺序(部分)

///////当应用程序接在完成时触发
- (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

时间: 2024-12-19 17:34:57

代码运行顺序(部分)的相关文章

zerglurker的C语言教程007——代码运行的顺序

软件开发中.代码有三种基本运行顺序: 顺序运行 代码从入口開始一条一条运行.直到返回或者结束 循环运行 在设定条件后,代码反复运行某一个或多个部分,直到达到某些条件后终止 条件运行 代码会先推断某些条件,假设满足则运行部分代码,假设不满足则运行还有一部分代码 实际其中,这三种运行顺序是交错出现的.你中有我,我中有你. 以下是上节课的代码,我们来一句一句的分析看.你就会明确我上面说的是什么了: #include <stdio.h> #include "public.h" in

Java知多少(23)类的基本运行顺序

我们以下面的类来说明一个基本的 Java 类的运行顺序: 1 public class Demo{ 2 private String name; 3 private int age; 4 public Demo(){ 5 name = "微学苑"; 6 age = 3; 7 } 8 public static void main(String[] args){ 9 Demo obj = new Demo(); 10 System.out.println(obj.name + "

当C#中带有return的TryCatch代码遇到Finally时代码执行顺序

编写的代码最怕出现的情况是运行中有错误出现,但是无法定位错误代码位置.综合<C#4.0图解教程>,总结如下: TryCatchFinally用到的最多的是TryCatch,Catch可以把Try代码块的错误捕捉到,并对错误进行后续处理.这一点比较常见. 现在要讨论的是如果Try和Catch代码块有return时代码的执行顺序.众所周知,return的作用是退出当前函数,不执行return后面的代码.那么问题来了:如果return出现在Try或catch代码块中,并且return后面还有代码,则

Eclipse下printf和scanf的运行顺序问题

Eclipse下printf和scanf的运行顺序问题 Eclipse  宇托  2011-12-25  662浏览  去评论 在写一个C语言时,运行时发现scanf比printf先执行了,在网上找了一下资料,原来是输出缓冲区的问题.解决方法有两个,第一,设置缓冲区为空,即没有缓冲区:第二,每执行printf之后,强制缓冲区.具体方法如下: 在printf之前添加:setvbuf(stdout,NULL,_IONBF,0);设置缓冲区为空. 在每句printf之后添加:fflush(stdout

javascript--函数的声明及调用/JS中代码执行顺序

[函数的声明及调用] 1.函数声明格式: function 函数名(参数1,参数2,参数3--){ //函数体 return 结果: } 函数调用的格式: 函数名(参数1的值,参数2的值,--): 事件调用:事件名=函数名(): 2.函数声明的几点强调: ① 函数的声明,必须符合小驼峰法则(首字母小写,之后每个单词首字母大写): ② 参数的列表,可以有参数,可以无参数.分别称为有参函数,无参函数: ③ 声明函数时的参数列表,称为"形参列表"(变量的名): 调用函数时的参数列表,称为&q

unity脚本运行顺序具体的解释

unity脚本自带函数执行顺序例如以下:将以下脚本挂在随意物体执行就可以得到 Awake ->OnEable-> Start ->-> FixedUpdate-> Update  -> LateUpdate ->OnGUI ->Reset -> OnDisable ->OnDestroy using UnityEngine; using System.Collections; public class timetest : MonoBehavio

5.Java类的基本运行顺序

我们以下面的类来说明一个基本的 Java 类的运行顺序: public class Demo{ private String name; private int age; public Demo(){ name = "微学苑"; age = 3; } public static void main(String[] args){ Demo obj = new Demo(); System.out.println(obj.name + "的年龄是" + obj.age

java实例化对象时程序运行顺序

当java实例化对象时,首先先进行类加载,类加载的整个过程是将类字节码引入内存,并未类中的static变量赋值.上篇文章已经大概分析了类的加载机制,下面讲一下类的实例化过程. 首先引入示例代码 父类 package test; public class Fu { public int j = 9; public static int i = 10; static{ i = 9; System.out.println("Fu静态代码块"); } { j = 10; System.out.

JS 和 a href className JS编写顺序与运行顺序 字符串或变量嵌入中括号 代替 点号

JS 和 a href 在href里面注意分号结尾, 引号闭合 <a href="javascript:;">空链接</a> <a href="javascript:alert('a');">弹出</a> 一般不妨代码, 一般让它空着. 空着也可以用井号'#', 但不是很好. className <style> #div1 {width:100px; height:100px; border:1px sol