将[super viewDidLoad]放入UIViewController的位置是否有所不同? [英] Does it make a difference where to put [super viewDidLoad] in my UIViewController?

查看:65
本文介绍了将[super viewDidLoad]放入UIViewController的位置是否有所不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
[super viewDidLoad]约定

在我的UIViewController的 viewDidLoad 中放置 [super viewDidLoad] 会有所不同吗?也就是说,它应该在方法的开头(在我的代码设置UIViewController之前)还是结束(在我的代码设置UIViewController之后)之后,还是没有任何区别?

Does it make a difference where I put [super viewDidLoad] within the viewDidLoad in my UIViewController? I.e., should it go at the beginning (before my code to set up the UIViewController) or the end )after my code to set up the UIViewController) of the method, or does it not make any difference?

推荐答案

通常应尽早调用super.否则,超类可能会干扰您自己的实现.假设 UIViewController 将在 viewDidLoad 中设置默认背景色(没有):如果您要在方法中设置自己的背景色,然后调用super,它将会重置为默认颜色,这可能会导致混淆.

You should usually call super as early as possible. Otherwise, the superclass may interfere with your own implementation. Let's say UIViewController would set a default background color in viewDidLoad (it doesn't): if you'd set your own background color in your method and then call super, it would be reset to the default color which could lead to confusion.

这篇关于将[super viewDidLoad]放入UIViewController的位置是否有所不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆