iOS APP及视图控制器生命周期

APP生命周期六大通知及回调函数

UIApplicationDidFinishLaunchingNotification 启动完毕

UIApplicationDidEnterBackgroundNotification 程序进入后台

UIApplicationWillEnterForegroundNotification 程序进入前台

UIApplicationDidBecomeActiveNotification 程序进入活跃状态

UIApplicationWillResignActiveNotification 程序进入非活跃状态

UIApplicationWillTerminateNotification 程序即将退出

UIApplicationDidReceiveMemoryWarningNotification 内存警告


1.启动完毕回调

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

2.程序进入非活跃状态(挂起状态)

-(void)applicationWillResignActive:(UIApplication*)application;

3.程序进入后台

-(void)applicationDidEnterBackground:(UIApplication*)application;

4.程序进入前台

-(void)applicationWillEnterForeground:(UIApplication*)application;

5.程序进入活跃状态

-(void)applicationDidBecomeActive:(UIApplication*)application;

6. 程序即将退出

-(void)applicationWillTerminate:(UIApplication*)application;

7.内存警告

-(void)applicationDidReceiveMemoryWarning:(UIApplication*)application;


视图控制器生命周期及执行顺序

1.当使用storyBoard时,调用函数如下:

-(instancetype)initWithCoder:(NSCoder*)aDecoder;

当使用xib和纯代码时,调用函数如下:

-(instancetype)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil;

2.xib加载完成时系统自行调用,纯代码不会调用函数如下:

-(void)awakeFromNib;

3.加载控制器视图

-(void)loadView;

4.控制器视图加载完成

-(void)viewDidLoad;

5.控制器视图将要出现

-(void)viewWillAppear:(BOOL)animated;

6.控制器视图将要加载设置子视图

-(void)viewWillLayoutSubviews;

7.控制器视图已经加载设置子视图

-(void)viewDidLayoutSubviews;

8.控制器视图已经出现

-(void)viewDidAppear:(BOOL)animated;

9.控制器视图将要消失

-(void)viewWillDisappear:(BOOL)animated;

10.控制器视图已经消失

-(void)viewDidDisappear:(BOOL)animated;

11.控制器资源销毁

-(void)dealloc;

你可能感兴趣的:(iOS APP及视图控制器生命周期)