2016.01.04 视图控制器UIViewController

视图控制器UIViewController 

The UIViewController class provides the infrastructure for managing the views of your iOS apps

视图控制器就是用来管理iOS程序中的视图,默认一个UIViewController为我们提供了一个视图UIView

我们称为根视图(root view)

It is responsible for loading and disposing of those views, for managing interactions with those views, and for coordinating responses with any appropriate data objects

视图控制器负责视图的加载和销毁,管理视图和用户的交互,协调相应数据对象的响应

 

视图控制器的lifecycle生命周期:控制器从出现到消失的整个过程

 

loadView

1.不能直接调用loadView

2.当一个控制器没有提供默认的视图,当显示的时候,需要这个视图,那么系统会调用loadView

   因此loadView是用来为这个界面创建一个默认的视图,也就是给视图控制器的根视图重新复制

   (创建一个新的view给控制器的view property)

 

viewDidLoad

自己手动创建视图或者从nib文件里面读取视图

 

viewWillAppear

界面即将展现在用户的面前

perform custom tasks associated with displaying the view

 

viewDidAppear

界面已经显示出来

 

viewWillDisAppear

界面即将消失

 

viewDidDisAppear

界面已经消失了

原文地址:https://www.cnblogs.com/immustard/p/5138567.html