当前位置: 代码迷 >> Iphone >> iphone开发中loadView跟viewDidLoad的区别
  详细解决方案

iphone开发中loadView跟viewDidLoad的区别

热度:70   发布时间:2016-04-25 06:25:25.0
iphone开发中loadView和viewDidLoad的区别
  我通过网上一搜就搜到
http://blog.csdn.net/zhanglei5415/archive/2011/02/17/6191726.aspx
和 http://blog.prosight.me/index.php/2009/11/492

viewDidLoad 此方法只有当view从nib文件初始化的时候才被调用。
loadView 此方法在控制器的view为nil的时候被调用。 此方法用于以编程的方式创建view的时候用到。

幸亏我查了下官方文档啊,不然我就被骗了呀.

引用
viewDidLoad
Called after the controller’s view is loaded into memory.

- (void)viewDidLoad
Discussion
This method is called after the view controller has loaded its associated views into memory. This method is called regardless of whether the views were stored in a nib file or created programmatically in the loadView method. This method is most commonly used to perform additional initialization steps on views that are loaded from nib files.


引用
loadView
Creates the view that the controller manages.

- (void)loadView
Discussion
You should never call this method directly. The view controller calls this method when the view property is requested but is currently nil. If you create your views manually, you must override this method and use it to create your views. If you use Interface Builder to create your views and initialize the view controller—that is, you initialize the view using the initWithNibName:bundle: method, set the nibName and nibBundle properties directly, or create both your views and view controller in Interface Builder—then you must not override this method.

The default implementation of this method looks for valid nib information and uses that information to load the associated nib file. If no nib information is specified, the default implementation creates a plain UIView object and makes it the main view.

If you override this method in order to create your views manually, you should do so and assign the root view of your hierarchy to the view property. (The views you create should be unique instances and should not be shared with any other view controller object.) Your custom implementation of this method should not call super.

If you want to perform any additional initialization of your views, do so in the viewDidLoad method. In iOS 3.0 and later, you should also override the viewDidUnload method to release any references to the view or its contents.
  相关解决方案