Iphone开发(二)从helloWorld看app应用的运行轨迹和生命周期

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 15:30 点击:

又要helloWorld了,每一个编程语言都逃不了这个宿命,今天我们通过helloworld来简单看一下iphone应用的生命周期和运行轨迹。

首先创建一个target:

 
建好之后我们会发现生成

好了,下面我们来对照生命周期图来研究这个项目:

  

 

首先,main方法是程序的入口,我们在main.m中会看到这样的代码:


[cpp] #import <UIKit/UIKit.h>  
 
#import "AppDelegate.h"  
 
int main(int argc, char *argv[]) 

    @autoreleasepool { 
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 
        //NSStringFromClass 其实只是得到AppDelegate类名。  
    } 

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        //NSStringFromClass 其实只是得到AppDelegate类名。
    }
}
在main中执行一个方法UIApplicationMain,该方法返回一个UIApplication对象表示我们的这个应用,第四个参数是一个字符串,提示我们去该字符串表示的类中寻找下一步的线索:application:DidFinishLaunchingWithOptions。我们发现该类名为AppDelegate,现在我们找到该类发现里面是如下内容:


[plain] #import "AppDelegate.h" 
 
#import "ViewController.h" 
 
@implementation AppDelegate 
 
@synthesize window = _window; 
@synthesize viewController = _viewController; 
 
- (void)dealloc 

    [_window release]; 
    [_viewController release]; 
    [super dealloc]; 

 
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];//1 
    // Override point for customization after application launch. 
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];//2 
    self.window.rootViewController = self.viewController;//3 
    [self.window makeKeyAndVisible];//4 
    return YES; 

 
 
 
@end 
#import "AppDelegate.h"

#import "ViewController.h"

@implementation AppDelegate

@synthesize window = _window;
@synthesize viewController = _viewController;

- (void)dealloc
{
    [_window release];
    [_viewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];//1
    // Override point for customization after application launch.
    self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];//2
    self.window.rootVie

    相关新闻>>

      发表评论
      请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
      用户名: 验证码:点击我更换图片
      最新评论 更多>>

      推荐热点

      • Lexical or Preprocessor Issue 'xxx.h
      • ios学习笔记(二)xcode 4.3.2下实现基本交互
      • ios版本的helloworld
      • iphone(object-c) 内存管理(3) 有效的内存管理 前半部分
      • ios学习笔记(一)xcode 4.3.2下创建第一个ios项目
      • IOS类似iphone通讯录TableView的完整demo【附源码】
      • UITableView一些方法
      • [iPhone中级]iPhone团购信息客户端的开发 (二)
      • 如何为Iphone应用创建启动界面
      网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
      Copyright © 2008-2015 计算机技术学习交流网. 版权所有

      豫ICP备11007008号-1