iOS架构

来源:互联网 发布:mac桌面下方图标隐藏 编辑:程序博客网 时间:2024/05/17 01:41

一个程序是从main函数中开始运行,iOS程序也是一样。当我们创建一个iOS工程后,会看到这样的结构:

可以看到main.m.

main.m:

#import <UIKit/UIKit.h>


#import "AZAppDelegate.h"


int main(int argc,char * argv[])

{

    @autoreleasepool {

        //在实际开发中,几乎是不会修改main函数的。

        returnUIApplicationMain(argc, argv, nil,NSStringFromClass([AZAppDelegateclass]));

        

        //第一、二个参数 argc,argv[]就是main函数传参,ios程序一般main函数是不会传参的

        

        //第三个参数如果传nil的话,那么UIApplicationMain会创建一个UIApplication类的对象。如果不传nil,必须传入UIAoolication类的子类class。函数会创建一个UIApplication子类的对象。

        

        // UIApplication类的对象,会监听系统修改当前应用状态时发送的通知。比如系统将应用程序切换到前台,切换到前台,来电打断

        

        //第四个参数是一个代理类的classUIApplication会创建一个代理对象

        

        

       /*

            AZAppDelegate的对象会成为UIApplication对象的代理,当Appplication的对象监听到系统发送的通知,即检测到当前应用程序状态改变,会委托AZAppDelegate的对象调用相应的方法。

         

         */

    }

}



AppDelegate.m:

#pragma mark - 以下都是实现UIApplicationDeleGate协议的方法


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

{

    NSLog(@"这个程序即将被载入内存,调用这个方法");

    

    //创建一个窗口对象,iOS程序一般只有一个窗口。

    self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColorwhiteColor];

    

    

    [self.windowmakeKeyAndVisible];

    return YES;

}


- (void)applicationWillResignActive:(UIApplication *)application

{

    NSLog(@"当程序即将停止活动状态,调用这个方法");

    

    // 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(@"当程序已经进入后台,调用这个方法");

    // 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(@"当程序即将回到前台,调用这个方法");

    // 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(@"当程序恢复活动时,调用这个方法");

    // 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(@"当内存不足,程序要崩溃,会先调用这个方法,在这个方法里可以释放一些内存,来尽量挽救这次崩溃");

    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}






0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 身体爱出油衣服领子总爱脏怎么办 白色衣服衣领净洗后变红怎么办 棒球服衣领洗变形怎么办 挂盐水手肿了怎么办 衣服买大了肩宽怎么办 买来的衣服肩宽怎么办 素描揉擦之后的黑点怎么办 扭脖子响了一下怎么办 画的眼线容易掉怎么办 做完眼线后眼睛肿了怎么办 洗眼线眼睛肿了怎么办 眼线留眼泪总是爱花妆怎么办 戴眼镜眼球外凸怎么办 修眉后的眉渣怎么办 内眼线容易晕妆怎么办 手抖不会画眼线怎么办 画眼线眼睛总眨怎么办 画眼线总是晕妆怎么办 眼线笔没用完干了怎么办 新的眼线笔干了怎么办 不涂口红没气色怎么办 眼线笔容易晕妆怎么办 眼线笔老是晕妆怎么办 眼线液老是晕妆怎么办 旋转眼线笔断了怎么办 眼睛去皮以后眉眼距窄怎么办 速写型总是画不准怎么办 速写人物不会打形怎么办 鼻头又圆又大怎么办 耳鸣嘴溃疡眼流泪上火怎么办 孩子看电视总挤眼睛怎么办 小孩老是咳嗽有痰怎么办 长时间看手机眼睛模糊怎么办 长时间看电脑眼睛模糊怎么办 手机玩多了眼睛模糊怎么办 手机看多了眼睛模糊怎么办 孩子玩手机眼睛红怎么办 手机玩多了眼睛红怎么办 手机看久了眼花怎么办 玩手机眼睛近视了怎么办 近视了怎么办30个字