您的位置:首页 > 移动开发 > IOS开发

loadView & ViewDidLoad

2016-08-02 18:31 393 查看
参考
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/loadView
- (void)loadView

Creates the view that the controller manages.

You should never call this method directly. The view controller calls this method when its view property is requested but currently nil.

The method loads or creates a view assigns it to the view property.

该方法用来创建供controller使用的视图。

不能直接调用该方法。 当需要使用view属性但是该属性值为nil时,view controller会调用此方法。该方法加载或创建一个view然后将

它赋值给view属性。

- (void)viewDidLoad

Called after the controller's view is loaded into memory.

This method is called after the view controller has loaded its view hierarchy into memory. This method is called regardless of whether

the view hierarchy was loaded from a nib or created programmatically in the loadView method. You usually override this method to 

perform additional initialization on views that were loaded from nib files.

在controller的视图被加载到内存中时被调用

这个方法在view controller的视图层级加载到内存中时被调用。不论视图层级是从nib文件中加载还是在loadView方法中用代码创建。

通常重写这个方法对从nib文件中加载的视图进行额外的初始化。

那么它们之间有什么联系。

UIViewController *controllerA = [[UIViewController alloc]  init];

controllerA.view.backgroundColor = [UIColor blackColor];
//此时会调用loadView方法和viewDidLoad方法

controllerA.view.backgroundColor = [UIColor orangeColor]; //此时不会调用loadView方法和viewDidLoad方法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios