Why is my UIViewController view unloaded when it is visible?

This question has never succeeded. I have a UIViewController inside a UINavigationController. When a warning about saving memory is received (do not pay attention to the level), the viewDidUnload method of the controller is called, the viewDidUnload therefore unloaded, and I get an amazing black screen (with the navigation bar at the top).

I am testing iPad 1 on iOS 4.3.3.

Any suggestions?

+6
source share
3 answers

From what I understand, the viewDidUnload method viewDidUnload called by the didRecieveMemoryWarning function in the UIViewController (superclass). Basically, iOS gives you a couple of warnings and expects your memory usage to decrease. If you continue to ignore them, the OS will kill your application.

Sometimes, however, it is very important that some views are displayed and executed, so I can get around this just to override the didRecieveMemoryWarning method and do nothing inside it.

Or better yet, check if self current view in self.navigationController.visibleViewController , and if so, do not pass the warning memory call before [super didRecieveMemoryWarning] .

If you hold image caches or something else, just leave them.

NTN

+1
source

According to Apple recommendations for managing memory, when the viewcontroller receives warnings about memory in critical situations, it directly calls viewDidUnload to manage memory by freeing up the view.

In fact, this ios gives you the opportunity to clear your temporary data, which will be useful in reconstructing the view. Since your UIViewCotroller is the root of the viewcontroller navigationcontroller , you see that the navigation bar looks unloaded.

0
source

You get viewDidUnload in a low memory situation on controllers where iOS has determined that views are no longer needed. Remember that Apple made some improvements to the implementation on later versions of iOS, so it could be worse than what happens under 5.x. Secondly, you should look at the hierarchy of your controller.

0
source

Source: https://habr.com/ru/post/921926/


All Articles