When is viewDidLoad called?(何时调用 viewDidLoad?)
问题描述
假设 chatViewController 的属性,即
,假设它在 fetchedResultsController
是否安全,UITableViewController
的子类的实例总是 UITableViewController
调用 viewDidLoad
时的 code>nilviewDidUnload
中设置为 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?
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01