InitWithNibName and viewDidLoad? [duplicate]

2019-05-25 07:34发布

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

2条回答
叛逆
2楼-- · 2019-05-25 08:04

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.

查看更多
放我归山
3楼-- · 2019-05-25 08:06
    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.

查看更多
登录 后发表回答