the Benifits of awakeFromNib?

后端 未结 1 1497
我寻月下人不归
我寻月下人不归 2021-02-09 12:18

I\'ve been learning coredata by making a lot of simple test apps based on the xcode Navigation controller template with \"use coredata\" checked.

The awakeFromNib method

相关标签:
1条回答
  • 2021-02-09 12:38

    All the methods fire at different times and different circumstances.

    awakeFromNib is called when the nib file associated with a class is loaded from disk. Any class that can own a nib can use it. viewDidLoad is used only by view controllers. It is usually called when loading from nib as well but it can also be called by a view created in memory (very rare circumstance.)

    In either case, you only put functionality in either that you only want to run once when the instance is first loaded. E.g. a common nubie mistake is to put code in viewDidLoad that needs to run every time the view appears. Say as with master view that opens a detail view and then reappears when the detail view is dismissed. If the code for the master view is in viewDidLoad it will only run the first time the master view is loaded but not any of the subsequent times the master view disappears and reappears.

    You generally don't initialize any other views or do much of anything in the app delegate's awake from nib. That is usually performed in applicationDidFinishLaunching.

    0 讨论(0)
提交回复
热议问题