我需要打电话给[super viewDidUnload]吗? [英] Do I need to call [super viewDidUnload]?

查看:110
本文介绍了我需要打电话给[super viewDidUnload]吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了一些 Apple 例子,它们确实调用了[super viewDidUnload];,而有些则没有.我读了一篇文章(几个月前,所以我不记得该URL了),该文章说调用[super viewDidUnload];是不必要的,但除此之外并没有解释.

I have seen some Apple examples that do call [super viewDidUnload]; and some that don't. I read an article (a few months ago so I dont recall the url) that said calling [super viewDidUnload]; was unnecessary but it didn't explain beyond that.

是否有明确的理由为什么或为什么不告诉超级人viewDidUnload?
而且,(如果应该完成 ),在将所有属性设置为nil之前,之后还是有关系吗?

Is there a definitive reason why or why not to tell super that the viewDidUnload?
And, (if it should be done) do I call super before setting all my properties to nil, after, or does it matter?

- (void)viewDidUnload {
    // Is this necessary?
    // [super viewDidUnload];

    self.tableDataSource = nil;
    self.titleLabel = nil;

    // Is it better to call super before or after nil'ing properties?
    // [super viewDidUnload];
}

谢谢!

推荐答案

1-是否有明确的原因为什么或为什么不告诉super viewDidUnload?

老实说,我不知道不打电话的后果.您可以尝试不调用它,并且一切运行顺利,但可以想象一下,苹果添加了一些重要的代码,这些代码将在调用[super viewDidUnload]时运行,现在会发生什么?坏事可能会发生,您将花费宝贵的时间来尝试解决问题.我的规则是:覆盖时,调用上级.

Honestly I don't know the consequences of not calling it. You can try to not call it and everything works smooth, but imagine that Apple adds some importante piece of code that will run when [super viewDidUnload] is called, what will happen now? Bad things will happen probably and you will spend precious time trying to solve your problem. My rule is: when overriding, call the super.

2-在将我的所有属性设置为nil之前,之后还是重要之前,我应该打电话给super吗?

这很重要,我看到释放对象之前调用[super dealloc]]时会发生坏事.以同样的方式看到UI变慢的原因是因为我在[super viewDidLoad]之前进行了计算.它始终取决于您要实现的目标.

It does matter, I have watched bad things happen when I called [super dealloc] before releasing my objects. The same way I saw my UI being slow because I did my calculations before [super viewDidLoad]. It always depend of what you want to achieve.

最重要的是,我在viewDidUnload项目中所做的是:

Bottom line, what I do in my projects for viewDidUnload is:

//释放我的观点

//release my views

[super viewDidUnload];

[super viewDidUnload];

对于iOS6:

该方法已被弃用.

这篇关于我需要打电话给[super viewDidUnload]吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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