Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my UIViewController's view is being unloaded when visible?

This issue never happened to me. I have an UIViewController inside an UINavigationController. When a memory warning is received (nevermind the level), the viewDidUnload method of the visible controller is called, so the view is unloaded and I get an awesome black screen (with a navigation bar at the top).

I'm testing with an iPad 1 on iOS 4.3.3.

Any suggestions?

like image 955
emenegro Avatar asked Aug 02 '12 09:08

emenegro


1 Answers

From what I understand, the viewDidUnload method is called by didRecieveMemoryWarning function in the UIViewController (the super class). Basically iOS gives you couple of warnings and expect to see your memory usage go down. If you continue to ignore these, OS will kill your app.

Sometimes, though, it is critical to keep some views up and running so the way I get around this is to simply override the didRecieveMemoryWarning method and inside it, don't do anything.

Or better yet, check if self is the current view in the self.navigationController.visibleViewController, and if so, don't pass the memory warning call down to [super didRecieveMemoryWarning].

If you are holding image caches or something, just empty those instead.

HTH

like image 88
dineth Avatar answered Oct 04 '22 02:10

dineth