Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewDidLoad in iOS 6 called once?

Head's up: This question is related to the recent deprecation of viewDidUnload. I have seen "great" and logical answers around this topic, but apparently they were proven wrong. Proceed with caution, this topic is very confusing as you see.

From Apple's Docs:

However, the system automatically releases these expensive resources when the view is not attached to a window. The remaining memory used by most views is small enough that it is not worth it for the system to automatically purge and recreate the view hierarchy.

So... Can I safely assume in iOS 6 that, as long as I don't explicitly set the viewController's view to nil (unload it manually), viewDidLoad will only be called only once for any allocated viewController instance throughout the lifetime of the application?

like image 729
Mazyod Avatar asked Oct 31 '12 06:10

Mazyod


People also ask

Is viewDidLoad called once?

viewDidLoad() is one of the initialization methods that is called on the initial view controller. viewDidLoad() is called before anything is shown to the user - and it is called only once.

What is called after viewDidLoad?

Always called after viewDidLoad (for obvious reasons, if you think about it), and just before the view appears on the screen to the user, viewWillAppear is called. This gives you a chance to do any last-minute view setup, kick off a network request (in another class, of course), or refresh the screen.

Is viewDidAppear called after viewDidLoad?

viewDidLoad is called after your view is loaded. It is called only once when view is initialized and pushed or presented. viewDidAppear is called once you see the loaded view on screen. It is called after view appeared.

Which is called first viewDidLoad or viewDidAppear?

The difference between viewDidAppear and viewDidLoad is that viewDidAppear is called every time you land on the screen while viewDidLoad is only called once which is when the app loads.


1 Answers

As of iOS 6, your UIViewController subclass will only receive viewDidLoad once, unless you write code to set its view back to nil.

However, I wouldn't rely on that behavior in a complex system-provided view controller like UIImagePickerController. Perhaps it sets its own view back to nil.

like image 88
rob mayoff Avatar answered Oct 19 '22 06:10

rob mayoff