InitWithNibName and viewDidLoad? [duplicate]

大城市里の小女人 提交于 2019-12-10 10:57:58

问题


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


回答1:


    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.




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!