My app has several UIViewControllers in a stack (under a UINavigationController). In certain cases I get memory warnings when I’m in the inner UIViewControllers (mostly happens if the device is overloaded with other applications running in the background). When these memory warnings occur the application keeps on running (most of the times) and then when it gets back to the rootViewController it reloads it but doesn’t fill in the view objects (mostly UIButton images).
I wish to implement didReceiveMemoryWarning and applicationDidReceiveMemoryWarning, but I’m not clear regarding to how to do that.
The end result I’m looking for is that when the application does this “reload” after memory warning it will “reload” rootViewController in the same status it was before the user started “diving” into the inner UIViewControllers.
- How should I do the implementation?
- Should I implement the default
didReceiveMemoryWarningin each UIViewController? - Since the memory warning always occur in the inner UIViewControllers, how should I let the
rootViewControllerknow that it should rundidReceiveMemoryWarning? - How do I tell the
rootViewControllerwhich settings it should do? In other words – can I keep the settings someplace wheredidReceiveMemoryWarningdoesn’t delete them and upon activatingdidReceiveMemoryWarning“recall” them so the user will see the same screen they started the “levels navigation” from?
Any non-visible view controller on the UINavigationController stack will dump its view. It will also send you the warning. If you have large data structures being held by the view controllers you should dump those if possible.
The root (an other) controllers should appropriately handle
viewDidUnloadand be able to cycle through anotherloadView/viewDidLoadphase.If you want the state to be the same, you need to be persisting all that information. NSUserDefaults is a standard location to do that.