我应该在自己的代码之后还是之前调用[super superMethod]?

编程入门 行业动态 更新时间:2024-10-24 10:23:25
本文介绍了我应该在自己的代码之后还是之前调用[super superMethod]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

[对不起我的英语不好]

[sorry for my weak english]

这个问题很简单(但是我很难在Google中表达它并找到它)...

The question is simple (but I have troubles in expressing it and finding it in google)...

我(在所有类似情况下,当我重写super方法时,不仅要使用此方法)应该使用:

Should I (in all similar cases, when I override the super method, not only this one) use:

- (void)viewDidLoad { /* my code */ [super viewDidLoad]; }

- (void)viewDidLoad { [super viewDidLoad]; /* my code */ }

还是取决于?

推荐答案

在某些情况下,顺序无关紧要.在其他情况下,顺序至关重要.

in some cases the order will not matter. in others, order is critical.

一些概括将有助于:

  • 在构造对象状态的一部分(viewDidLoad和init...)时,请先通过super调用.
  • 破坏对象状态的一部分(viewDidUnload或dealloc)时,最后通过super调用.
  • 如果我确定顺序无关紧要,那么我只需先通过super致电即可,以便于组织.
  • when you are constructing a portion of the object's state (viewDidLoad and init...), call through super first.
  • when you are destructing a portion of the object's state (viewDidUnload or dealloc), call through super last.
  • if i am certain that the order does not matter, then i just call through super first for easier organization.

更多推荐

我应该在自己的代码之后还是之前调用[super superMethod]?

本文发布于:2023-10-27 11:37:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533242.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自己的   代码   superMethod   super

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!