In the iPhone SDK, can anyone explain the difference between application DidFinishLaunching in delegate and ViewDidLoad method in ViewControler?
4 Answers
applicationDidFinishLaunching is called by the App Delgate when your application has finished launching. This method is useful for doing setup as soon as possible. Examples of this could include setting up GameCenter, and doing some first launch checking.
viewDidLoad is called by a UIViewController after the view is loaded, usually from the nib. However, in some cases, you may want to do setup before the view is loaded. In that case, use
viewWillLoad is called just before the view is loaded, usually from the nib. For the most part, it will not make much of a difference wether you use viewDidLoad or viewWillLoad. However, some setup may have to be done after the view is loaded and other setup you may want to do before the screen displays anything.
applicationDidFinishLaunching is for initial appwide setup, viewWillLoad is for setup before the view is displayed, and viewDidLoad is for setup right after the view is loaded.

- 3,308
- 2
- 26
- 44
-
1"view is loaded **from the nib**" - not true, view can be created programmatically and `viewDidLoad:` will be called too. – Andrey Zverev Dec 15 '11 at 07:47
-
1The **viewWillLoad** function has been replaced by **viewWillAppear** in **Swift** – mccoyLBI Sep 21 '16 at 15:06
-
1viewWillAppear is different from viewWillLoad. It will be called after viewDidLoad but before viewDidAppear, as opposed to before viewDidLoad. – WolfLink Sep 23 '16 at 00:25
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
gets called when your app is finished launching; and viewDidLoad:
gets called when an UIView
controlled by UIViewController
is loaded.

- 4,409
- 1
- 28
- 34
viewDidLoad is the method that is called once the view has been loaded. It is a place where you can insert code that does initial setup of the view once it has been loaded.
The applicationDidFinishLaunching: method of the NSApplication delegate will be called when the app has finished loading.

- 301
- 2
- 11
-
can i insert the code in DidFinishlaunching that do the initial set up?? – Karthik Varma Dec 15 '11 at 07:14
-
We can use UIApplication sharedApplication to access what u have declared in the appDelegate class. – Praveen Dec 15 '11 at 07:25
-
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Method available only in application AppDelegate it calles only ones at the time of app is loaded you can do all the stuff related to your application prelaunch here.
-(void)viewDidLoad: called whenever a view is loaded.
it also call ones when the view is loaded but it's has own copy for every viewController you can do any stuf related to that controller inside it.

- 244
- 1
- 2
- 8