`
alex09
  • 浏览: 978866 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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.
分享到:
评论

相关推荐

    iPhone开发、ObjectiveC_面试题目

    在iOS开发中,Objective-C是主要的编程语言之一,尤其对于iPhone应用开发。这里我们讨论的是Objective-C的一些核心概念和面试常问问题。 1. `alloc`与`dealloc`、`retain`与`release`的关系:`alloc`是创建对象并...

    iPhone开发【二】重写HelloWorld (不使用XIB)

    在iOS开发中,"Hello, World!" 是每个程序员初次接触新平台时的标志性程序,它标志着你的编程之旅正式开始。本篇文章将深入讲解如何在不使用XIB(XML Interface Builder)的情况下,重写一个基本的HelloWorld应用。...

    iphone视图控制器例子

    在iOS开发中,`iPhone视图控制器`是构建应用程序用户界面的核心组件,它负责管理屏幕上的内容和交互。本教程适合初学者,旨在通过实例帮助理解视图控制器的工作原理及其重要性。 首先,我们需要了解`...

    ios应用源码之一个简单的空白页面demo 2018127

    - 了解UIViewController的生命周期至关重要,如`awakeFromNib`, `loadView`, `viewDidLoad`, `viewWillAppear`, `viewDidAppear`等方法,这些方法在不同的阶段被调用,用于初始化视图和执行相关操作。 5. **Auto ...

    ios-CustomsheetView.zip

    - 可以在视图控制器的`loadView`或`viewDidLoad`方法中设置视图的初始状态和内容。 2. **自定义视图**: - 使用Swift或Objective-C创建一个UIView子类,定义你需要的布局和视图元素。 - 在`layoutSubviews`方法...

    iOS笔试题.docx

    9. 堆和栈的区别:栈由系统自动管理,分配和释放快速,存储局部变量和函数参数;堆由程序员手动管理,分配和释放较慢,用于动态内存分配,如对象实例。 10. Objective-C内存管理基于引用计数,使用`retain`、`...

    UIAlertView 的替代品

    在iOS开发中,UIAlertView曾是用于显示警告或确认消息的标准组件,但在iOS 8之后,苹果引入了新的UIPresentation API,弃用了UIAlertView,并推荐使用UIAlertController。因此,“UIAlertView的替代品”这一主题主要...

Global site tag (gtag.js) - Google Analytics