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?
- Android - 拆分 Drawable 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
