iOS 6弃用viewWillUnload&移动到didReceiveMemoryWarning [英] iOS 6 deprecation of viewWillUnload & move to didReceiveMemoryWarning

查看:138
本文介绍了iOS 6弃用viewWillUnload&移动到didReceiveMemoryWarning的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新开发人员要推出我的第一个应用程式。我对如下所述的 viewDidUnload 的弃用感到困惑:

I'm new developer about to launch my first app. I'm confused about the deprecation of viewDidUnload as described below in Apple's iOS 6 release notes:


在iOS 6中,
UIViewController的viewWillUnload和viewDidUnload方法现在已被弃用。如果您使用这些方法
释放数据,请改用didReceiveMemoryWarning方法。你
也可以使用这个方法来释放对
控制器视图的引用(如果没有被使用)。您需要测试
视图不在窗口中,然后才能执行此操作。

In iOS 6, the viewWillUnload and viewDidUnload methods of UIViewController are now deprecated. If you were using these methods to release data, use the didReceiveMemoryWarning method instead. You can also use this method to release references to the view controller’s view if it is not being used. You would need to test that the view is not in a window before doing this.

为什么会发生这种情况?我应该遵循什么准则,以确保此更改不会在我的应用程序中导致任何性能问题?

Why is this happening? What guidelines should I follow to ensure that this change doesn't cause any performance issues in my app?

感谢。

推荐答案

内部存储器管理足够的视图,通过销毁在 viewWill / DidUnload 中的东西所获得的收益是最小的。此外,他们有数据表明,许多应用程序崩溃,因为应用程序不能正确处理这些通知,并做其他的东西不与视图卸载相关联。

According to Apple, they have improved the internal memory management for views enough that the gains achieved by destroying stuff in viewWill/DidUnload are minimal. Furthermore, they have data suggesting that many apps crash because the apps do not properly handle those notifications, and do "other" stuff not associated with the view unloading.

现在验证内存警告是您的应用程序由于内存不足而终止之前的第一个也是唯一的警告,因此它是真正处理内存问题的地方。

Finally, a memory warning is now verified as the first and only warning you will get before your app is terminated due to low memory, so it is really the place to handle memory issues.

所以,基本上,只是删除你的 viewWillUnload viewDidUnload 方法。处理 didReceiveMemoryWarning 中的内存问题以及适当位置的任何其他视图控制器管理。

So, basically, just remove your viewWillUnload and viewDidUnload methods. Handle memory issues in didReceiveMemoryWarning and any other view controller management in the appropriate places.

EDIT

EDIT


我可以问:这些适当的地方是什么?我曾经使用
ViewdidUnload在某些情况下,视图[Will / Did]消失是
不完全足够。喜欢在导航
控制器堆栈进一步下降。你能介绍一下吗? -
Dan1one

May I ask: what are those "appropiate places"? I used to use ViewdidUnload in certain situations where view[Will/Did]Disappear were not entirely adequate. Like going further down on the navigation controller stack. Would you mind to elaborate further on that? – Dan1one

这取决于。我知道这不是你想听到的,但它是真的: - )

That depends. I know that's not what you want to hear, but it's the truth :-)

一般来说,你应该避免不对称。因此,您应该使用从其原样执行的对称方法撤消操作。一般来说,你应该能够在 didReceiveMemoryWarning 中的所有 viewDidUnload

In general, you should avoid asymmetry. Thus, you should "undo" an operation using the symmetric method from which you "did" the original. In general, you should be able to do all the viewDidUnload type work in didReceiveMemoryWarning and dealloc.

这真的不会导致改变,因为你必须在这两个地方重复大部分代码。

This should really not cause a change, because you had to duplicate most of that code in both of those places anyway.

我不知道你的意思是进一步下来在导航控制器堆栈,所以你需要澄清这个例子为我提供一个有用的反应。

I don't know what you mean by "going further down on the navigation controller stack" so you will need to clarify that example for me to provide a useful response.

使用 viewDidDisappear viewDidAppear 的一个问题是很难知道视图是否正在显示,因为它实际上正在显示,或者因为它顶部的视图正在消失...导致它出现。

One of the problems with using viewDidDisappear and viewDidAppear was that it was hard to know when the view was appearing because it was actually appearing, or because a view that was on top of it was disappearing... causing it to appear.

这些API应该帮助你解决这些问题:

These pieces of API are supposed to help you address those issues:

- (BOOL)isMovingFromParentViewController
- (BOOL)isMovingToParentViewController
- (BOOL)isBeingDismissed
- (BOOL)isBeingPresented

这篇关于iOS 6弃用viewWillUnload&移动到didReceiveMemoryWarning的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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