我总是要在-viewDidLoad方法中调用[super viewDidLoad]吗? [英] Do I always have to call [super viewDidLoad] in the -viewDidLoad method?

查看:126
本文介绍了我总是要在-viewDidLoad方法中调用[super viewDidLoad]吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Apple的scrollView示例中,他们不会调用它。我一直以为这是必须。为什么我还要调用它?

In Apple's scrollView example they don't call that. I always thought that's a must. Why should I call that anyways?

推荐答案

如果你重写方法,你仍然应该在super中调用方法。即使超级班今天没有对它做任何事情,Apple有一天可能会改变实施,你的代码将神秘地停止工作。如果您真的不需要在该方法中做任何事情,请将其完全保留在您的代码之外,并且super的方法将照常运行,无需您的任何干预。

If you are overriding the method you should still call the method in the super. Even if the super class is not doing anything with it today, Apple might one day change the implementation and your code will mysteriously stop working. If you really don't need to do anything in that method, leave it out of your code entirely, and the super's method will run as usual, without any intervention on your part.

这篇关于我总是要在-viewDidLoad方法中调用[super viewDidLoad]吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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