iPhone - viewDidUnload/viewDidLoad called inconsistently

半腔热情 提交于 2019-12-10 11:38:35

问题


I was doing some testing and debugging of my Iphone app today and encountered some strange behaviour.

In my MainView I have two modal views and when showing one of these using presentModalViewController I noted that the viewDidUnload method of my MainView was called while it was not happening when showing the other. It was the same case for the viewDidLoad method (of MainView) while closing the subviews.

I inspected the two methods for opening and closing the subviews and the only difference I found was in the modalTransitionStyle. In the one which did activate viewDidUnload/viewDidLoad I was using UIModalTransitionStyleFlipHorizontal and in the other UIModalTransitionStyleCrossDissolve. I then started experimenting by swapping the two styles and by using the other transition styles as well and I found that this was indeed what was causing the different behaviour. In fact when using UIModalTransitionStyleFlipHorizontal the viewDidUnload/viewDidLoad methods of the "parent" view controller were always called while it never happened for any of the other transition styles.

My question is now it this is supposed to behave like this, and if not which behaviour is then the correct one. Are the unload and load methods supposed to get called when showing and closing an modal view or not.

Also, could someone else confirm or disconfirm this behaviour?

Thanx

PS. the viewDidLoad method of the two called view controllers gets called every time. Just to clarify :)


回答1:


Are the unload and load methods supposed to get called when showing and closing an modal view or not.

The behavior should depend on the current memory situation. If memory is low, the system will send memory warnings to all view controllers. A view controller whose view is not currently on screen will react on the memory warning by unloading its view (which will cause a reloading of the view when it comes on screen again, obviously).

So depending on the memory situation of the device and the memory requirements of the modal view controller you are displaying, the unload/load behavior should vary. It should not depend on the modalTransitionStyle IMO.



来源:https://stackoverflow.com/questions/4699522/iphone-viewdidunload-viewdidload-called-inconsistently

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!