请逐步告诉我iOS的不同视图方法。请解释先执行哪个方法等。我的意思是说什么时候执行哪个方法?
问问题
820 次
2 回答
3
- Init 或 InitWithCode 或 InitWithNibName 或(任何初始化方法)
- loadView ///它只在你有自定义viewController并且你从nibFile加载自定义视图时调用,通常不调用loadView
- viewDidLoad
- 视图将出现
- viewDidAppear
在卸载侧
- 视图将消失
- viewDidDisappear
- viewDidUnload
- 释放
这些特定于 viewController 仅不适用于 tableView 或其他类型的 viewController。如果我缺少任何方法,请添加评论。
于 2011-03-08T06:04:53.197 回答
0
对于您的具体问题,您应该在 viewDidLoad 中添加子视图。因为,如果你覆盖 loadView,你必须做所有的工作,加载所有的视图。
在加载周期中发生的步骤如下:
1.
* Some part of your application asks for the view in the view
controller’s view property.
2.
* If the view is not currently in memory, the view controller calls its loadView
method.
3.
* The loadView method does one of the following:
If you override this method, your implementation is
responsible for creating all necessary views and assigning a non-nil value to the view property.
If you do not override this method, the default implementation uses
the nibName and nibBundle properties of the view controller to try to load the view from the specified nib file. If the specified nib file is not found, it looks for a nib file whose name matches the name of the view controller class and loads that file.
If no nib file is available, the method creates an empty UIView object
and assigns it to the view property.
4.
* The view controller calls its viewDidLoad method to perform any
additional load-time tasks.
于 2011-03-08T06:02:47.003 回答