Possible Duplicate:
initWithNibName VS viewDidLoad
I'm new at iOS development. I would just like to know the main differences between these 2 functions ?
Thanks for your help
viewDidLoad
Is called when the view loads and is initiated/Unarchived and loaded into the memory. This is a great customisation stop.
initWithNibName:
Is used for initializing a certain class ( it is an overriden init method) with a xib file's name, the bundle parameter specifies the location of the file, you would pass nil for the main bundle, which is the projects folder.
You should set up your properties in the viewDidLoad. The initWithNibName: is something that you call when you create a controller instance from a nib File. I wouldn't put customisation code there.
viewDidLoad:
viewDidLoad
is a part of iPhone application life cycle.This method is called after the .xib file is read and the outlets and actions are connected to your view controller. In this Method you can do assignment with your outlets. This method get called as many times as your view get Loaded and unloaded.
initWithNibName:
This method is the designated initializer for UIViewController classes. It's used whenever you're creating a UIViewController object in the code. This method sets up UIViewController to be able to load a nib on demand. This method is helpful when you are performing something different logic in init method.
来源:https://stackoverflow.com/questions/10684342/initwithnibname-and-viewdidload