UIViewController view視圖的加載

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章