【发布时间】:2011-03-08 05:58:07
【问题描述】:
请逐步告诉我iOS的不同视图方法。请解释先执行哪个方法等。我的意思是说什么时候执行哪个方法?
【问题讨论】:
标签: iphone methods view viewdidload
请逐步告诉我iOS的不同视图方法。请解释先执行哪个方法等。我的意思是说什么时候执行哪个方法?
【问题讨论】:
标签: iphone methods view viewdidload
在卸载端
这些特定于 viewController 仅不适用于 tableView 或其他类型的 viewController。如果我缺少任何方法,请添加 cmets。
【讨论】:
super 进行相同的调用,否则您将陷入无限循环。创建或显示某些东西的方法首先调用 super,然后执行任何操作。删除视图的方法使对 super 的调用最后。例如,viewWillAppear:(BOOL)animated 的第一行应该是[super viewWillAppear:animate],而viewWillDisappear:(BOOL)animated 的最后一行应该是[super viewWillDisappear:animated]。后者就像在你自己的dealloc 方法的最后一行调用[super dealloc]。
NSLog(@"will load")、NSLog(@"did load")、NSLog(@"will appear")、...每个,看看控制台是什么。
对于您的具体问题,您应该在 viewDidLoad 中添加子视图。因为,如果你覆盖了 loadView,你必须完成所有的工作,加载所有的视图。
这里是Apple's documentation:的解释
加载周期中发生的步骤如下:
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.
【讨论】: