为什么viewDidUnload的调用频率低于viewDidLoad? [英] Why is viewDidUnload called less often than viewDidLoad?

查看:70
本文介绍了为什么viewDidUnload的调用频率低于viewDidLoad?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把 NSLog(@%@ ::%@,[[self class] description],NSStringFromSelector(_cmd)); 放在<$ c $中c> viewDidLoad 和视图控制器的 viewDidUnload

I put NSLog(@"%@::%@", [[self class] description], NSStringFromSelector(_cmd)); in both viewDidLoad and viewDidUnload of a view controller.

在日志中,我当应用程序移入和移出不同的.nib时,发现 viewDidLoad 被调用远远超过 viewDidUnload

In the log, I found viewDidLoad is called a lot more than viewDidUnload when the app moves to and from different .nibs.

为什么?

推荐答案

viewDidLoad和viewDidUnload彼此不对应。

The viewDidLoad and viewDidUnload is not corresponding to each other.

只有在收到内存警告时才会调用viewDidUnload。然后系统将自动调用你的viewDidUnload。

The viewDidUnload will only be called when you receive a memory warning. The system then will automatically call your viewDidUnload.

在正常情况下,当你按下MyViewController并将其弹出时。生命周期将如下所示:

In the normal case, when you push a MyViewController and pop it out. The life cycle will happens like this:

init

viewDidLoad

release

这意味着,无论何时初始化和推送/呈现视图,都会调用viewDidLoad。但是当您弹出视图时,将在正常情况下调用该版本,并且将在内存警告情况下调用viewDidUnload。

That means, whenever you init and push/present a view, a viewDidLoad will be called. But when you pop the view, the release will be called in normal case and viewDidUnload will be called in memory warning case.

这是非常含蓄的,Apple没有声明它明确地在指南上。以下是一些参考:加载和卸载周期

This is quite implicit and Apple doesn't state it clearly on the Guide. Here is some reference: Load and Unload cycle

这篇关于为什么viewDidUnload的调用频率低于viewDidLoad?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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