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?
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
