何时调用 viewDidLoad?

When is viewDidLoad called?(何时调用 viewDidLoad?)

本文介绍了何时调用 viewDidLoad?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设 chatViewController 的属性,即 fetchedResultsController 是否安全,UITableViewController 的子类的实例总是 UITableViewController调用 viewDidLoad 时的 code>nil,假设它在 viewDidUnload 中设置为 nil?呸!

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 是否为 nil 取决于 viewController 的初始化方式.例如,在创建 detailViewController 时,您可以在调用 viewDidLoad 之前设置它的 fetchedViewController:

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 中将 fetchedResultsController 设为 nil 将确保它为 nil.

That said, then nil'ing fetchedResultsController in viewDidUnload would ensure that it's nil.

这篇关于何时调用 viewDidLoad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:何时调用 viewDidLoad?

基础教程推荐