开发者

View never reloaded (viewdidload never called) after viewdidunload called after memory warning

I have a main view controller with two other view controllers as member variables, representing different "tabs" within the main view. They are hidden and shown when the "tabs" are tapped. All of these are in a nib file.

When I get a memory warning, viewdidunload is called and the view is dumped, as expected. However, they are never recrea开发者_Python百科ted and viewdidunload is never called again. The main view controller is attached to a nav controller.

What gives?


When a memory warning occurs, the system may unloads views of view controller that are not visible on screen at that time. The action which triggers the reloading of those view controller's views is something actually trying to access those views. In other words, when some code is executed which accesses viewController.view, if that view had been unloaded, it is reloaded.

In practical terms, this means that your unloaded views will usually be automatically reloaded at the point where they would be shown again. So after a memory warning, change the current view using your tab controller variant, and you should see that it is reloaded (if it was indeed unloaded).


I solved this by dumping and reloading the associated view controllers on a memory warning, but the original cause remains a mystery.

Viewdidappear is never called on the views either, I suspect this is related to whatever the explanation is.


If you're doing view controller containment you have to manage the appearance and disappearance of your view controllers at all time.

When a view controller unloads its the view whole hierarchy of that view is destroyed and is, of course, not saved. When the view of that parent is reloaded, the -loadView and -viewDidLoad code are executed as well as the appearance methods. These methods will not do more than what you tell them to do. If you do not rebuild the view hierarchy of your children in viewDidLoad don't expect them to reappear magically.

The job of the container controller is to load the view of its children (the ones that are visible) and layout them in its own view.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜