1

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 :)

pajevic
  • 4,607
  • 4
  • 39
  • 73
  • does this happen in iOS simulator or device? which SDK are you using? – Felix Jan 15 '11 at 12:48
  • Please, tell us what version of the SDK you are using. It could also help if you show the actual code you are using to check whether viewDiDLoad and viewDidUnload have been called. – Alexei Sholik Jan 15 '11 at 13:06
  • @phix23: This is happening on an iPhone 4 (device) running iOS 4.2.1. I am using SDK 4.2. – pajevic Jan 15 '11 at 14:29
  • @Alex: SDK version 4.2. I am not actually using code to test this. Just have a breakpoint in these two methods. – pajevic Jan 15 '11 at 14:31

1 Answers1

0

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.

Ole Begemann
  • 135,006
  • 31
  • 278
  • 256
  • "It should not depend on the modalTransitionStyle" - I completely agree. However, it seems it does, at least in my case. I really did test this thouroly. I'm still hoping someone else has encountered this before. – pajevic Jan 15 '11 at 13:54