AppDelegate和ViewController生命周期

AppDelegate

  1. 应用程序启动,并进行初始化时调用该方法:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)

  1. 应用程序进入前台并处于活动状态时调用:

func applicationDidBecomeActive(application: UIApplication)

  1. 应用程序从活动状态进入到非活动状态:

func applicationWillResignActive(application: UIApplication)

  1. 应用程序进入到后台时候调用的方法:

func applicationDidEnterBackground(application: UIApplication)

  1. 应用程序进入到前台时候调用的方法:

func applicationWillEnterForeground(application: UIApplication)

  1. 应用程序将被终止的时候调用:

func applicationWillTerminate(application: UIApplication)

ViewController

loadView→viewDidLoad→viewWillAppear→viewDidAppear→viewWillDisappear→viewDidDisappear→dealloc

  1. loadView:一般情况下不用用到,除非需要重写设置View;
  2. viewDidLoad/dealloc:视图加载完成之后的设置和视图销毁的时候调用;
  3. viewWillAppear/viewWillDisappear:视图即将呈现和视图即将消失;
  4. viewDidAppear/viewDidDisappear:视图展现在屏幕的时候和视图完全消失在屏幕的时候调用,默认不做任何操作;

你可能感兴趣的:(AppDelegate和ViewController生命周期)