[super viewWillAppear]做什么,什么时候需要它? [英] What does [super viewWillAppear] do, and when is it required?

查看:273
本文介绍了[super viewWillAppear]做什么,什么时候需要它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-(void)viewWillAppear:(BOOL)animated{
//something here
[super viewWillAppear];
}

[super viewWillAppear]; 总是需要?

推荐答案

首先,正确的锅板应该是:

First of all, the correct boiler plate should be:

-(void)viewWillAppear:(BOOL)animated{
   [super viewWillAppear:animated];
   //something here
}

换句话说,调用 super ,然后自己做。您必须将动画参数传递给 super

In other words, call super first, then do your own thing. And you have to pass the animated parameter to super.

你通常想在任何方法中调用超类的实现。在许多语言中它是必需的。在Objective-C它不是,但你可以很容易遇到麻烦,如果你不把它放在你的方法的顶部。

You usually want to call the super class' implementation first in any method. In many languages it's required. In Objective-C it's not, but you can easily run into trouble if you don't put it at the top of your method. (That said, I sometimes break this pattern.)

正在调用 super's 实现必需?在这种特定方法的情况下,如果你不调用它,你可能会得到意想不到的行为(例如,如果你已经子类化一个 UINavigationController )。所以答案是没有不是在技术意义上,但你应该总是这样做。

Is calling super's implementation required? In the case of this particular method you could get unexpected behavior if you don't call it (especially if you have subclassed a UINavigationController for example). So the answer is no not in a technical sense, but you should probably always do it.

然而,在许多其他方法可能没有调用 super 的好理由。

However, in many other methods there may be good reasons for not calling super.

这篇关于[super viewWillAppear]做什么,什么时候需要它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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