init-初始化程序
viewDidLoad-加载视图
viewWillAppear-UIViewController对象的视图即将加入窗口时调用;
viewDidApper-UIViewController对象的视图已经加入到窗口时调用;
viewWillDisappear-UIViewController对象的视图即将消失、被覆盖或是隐藏时调用;
viewDidDisappear-UIViewController对象的视图已经消失、被覆盖或是隐藏时调用;
顺序如下:
//1 并且只调用一次
//每次访问UIViewController的view(比如controller.view、self.view)而且view为nil,loadView方法就会被调用。
-(void)loadView{
[super loadView];
NSLog(@"1");
}
//2 并且只调用一次
//不过你是通过xib文件还是重写loadView创建UIViewController的view,在view创建完毕后,最终都会调用viewDidLoad方法
//一般我们会在这里做界面上的初始化操作,比如往view中添加一些子视图、从数据库或者网络加载模型数据装配到子视图中
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(@"2");
}
//此方法经常调用
//3
//UIViewController对象的视图即将加入窗口时调用;
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"3");
}
//4
//subviews布局前调用
-(void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
NSLog(@"4");
}
//5
//subviews布局后调用
-(void)viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
NSLog(@"5");
}
//6
//UIViewController对象的视图已经加入到窗口中调用
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
static dispatch_once_t onceToken;
[self playWithAVPlayerViewController];
NSLog(@"6");
}
//7
//UIViewController的视图即将消失、被覆盖或是隐藏时调用
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
NSLog(@"7");
}
//8
//UIViewController对象的视图已经消失、被覆盖或是隐藏时调用;
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
NSLog(@"8");
}
- (void)loadView; // This is where subclasses should create their custom view hierarchy if they aren't using a nib. Should never be called directly.
- (void)viewDidLoad; // Called after the view has been loaded. For view controllers created in code, this is after -loadView. For view controllers unarchived from a nib, this is after the view is set.
- (void)viewWillAppear:(BOOL)animated; // Called when the view is about to made visible. Default does nothing
- (void)viewDidAppear:(BOOL)animated; // Called when the view has been fully transitioned onto the screen. Default does nothing
- (void)viewWillDisappear:(BOOL)animated; // Called when the view is dismissed, covered or otherwise hidden. Default does nothing
- (void)viewDidDisappear:(BOOL)animated; // Called after the view was dismissed, covered or otherwise hidden. Default does nothing
// Called just before the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a nop.
- (void)viewWillLayoutSubviews NS_AVAILABLE_IOS(5_0);
// Called just after the view controller's view's layoutSubviews method is invoked. Subclasses can implement as necessary. The default is a nop.
- (void)viewDidLayoutSubviews NS_AVAILABLE_IOS(5_0);
程序运行的结果
2016-10-26 16:21:01.696141 xjy[2662:542884] 1
2016-10-26 16:21:01.696467 xjy[2662:542884] 2
2016-10-26 16:21:01.696960 xjy[2662:542884] 3
2016-10-26 16:21:01.704862 xjy[2662:542884] 4
2016-10-26 16:21:01.705518 xjy[2662:542884] 5
2016-10-26 16:21:01.925914 xjy[2662:542884] 6
2016-10-26 16:21:02.030945 xjy[2662:542884] 7
2016-10-26 16:21:02.877219 xjy[2662:542884] 8