viewDidLoad何时被调用? [英] When is viewDidLoad called?
问题描述
是否可以安全地假设 chatViewController
的属性,即 fetchedResultsController
,是一个子类的实例 UITableViewController
,当 viewDidLoad
被调用时,总是 nil
,假设它在 viewDidUnload
中设置为 nil
? Phew!
Is it safe to assume that an attribute, namely fetchedResultsController
, of chatViewController
, an instance of a subclass of UITableViewController
, is always nil
when viewDidLoad
is called, assuming that it's set to nil
in viewDidUnload
? Phew!
如果是这种情况,那么我认为没有必要像Xcode示例应用程序CoreDataBooks那样重新定义访问器函数。我宁愿把所有代码放在 viewDidLoad
而不是单独的函数中,因为这是我唯一使用它的地方。
If that's the case, then I see no immediate need to redefine the accessor function like in the Xcode example application CoreDataBooks. I'd rather just put all that code in viewDidLoad
instead of in a separate function because that's the only place I'll use it.
推荐答案
加载视图后调用viewDidLoad。 fetchedResultsController是否为n取决于viewController的初始化方式。例如,在创建 detailViewController
时,可以在 viewDidLoad $之前设置其
fetchedViewController
c $ c>被调用:
viewDidLoad is called after your view is loaded. Whether or not fetchedResultsController is nil or not depends on how the viewController is initialized. For example, when creating the detailViewController
, you could set its fetchedViewController
before viewDidLoad
is called:
RecipeDetailViewController *detailViewController = [[RecipeDetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
detailViewController.fetchedResultsController = fetchedResultsController;
[self.navigationController pushViewController:detailViewController animated:animated];
[detailViewController release];
那就是说,然后在viewDidUnload中nil'ing fetchedResultsController将确保它为零。
That said, then nil'ing fetchedResultsController in viewDidUnload would ensure that it's nil.
这篇关于viewDidLoad何时被调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!