The problem is you are completely misunderstanding what viewDidUnload
means. viewDidUnload
is called when the view is unloaded. In pre-iOS 6, when you are done with a view controller, its view does NOT get unloaded. In pre-iOS 6, 99% of the time you will never see viewDidUnload
being run, because views are usually not unloaded. In pre-iOS 6, views are only unloaded in response to a memory warning and the view is not visible. In iOS 6, the only change is that views are never unloaded, even in a memory warning.
The behavior of viewDidUnload
is identical in pre-iOS 6 and iOS 6 -- it is called when the view is unloaded. Because of this, you should NOT have to change any code for iOS 6. If you do, you did something wrong.
Before iOS 6 I used to removeObserver of NSNotification in viewDidUnload method.
If what you mean is that you added the observer in viewDidLoad
, then you must have it removed in dealloc
. Otherwise your code will crash. As I said above, 99% of the time, in pre-iOS 6, views are not unloaded. The typical flow is init
-> viewDidLoad
-> dealloc
. The view does not get unloaded in the middle.
You can optionally also remove the observer in viewDidUnload
. It is a good idea because it returns it to the state before the view was loaded. However, it is not strictly necessary, because when the view loads again, viewDidLoad
will be called, and overwrite whatever state there was before anyway.
So the answer is, you should not have to change anything in response to iOS 6. Whatever you did in viewDidLoad
should be undone in both viewDidUnload
(optional) and dealloc
(required). This is true in both iOS 6 and pre-iOS 6.