One of the things that can really foul up your day as a developer is the order in which objects are called. If you expect an object to be there (and it isn’t) or to have been initialized (and it wasn’t), you may be in the wrong method. Copy Table 19-1 and paste it into a file — and/or print it out and tack it up where you can easily find it.
Table 19-1 | The Natural Order of Things |
Object | Method |
View Controller | awakeFromNib |
Application Delegate | applicationDidFinishLaunching: |
View Controller | viewDidLoad |
View Controller | viewWillAppear: |
View Controller | viewWillDisappear: |
Delegate | applicationWillTerminate: |
What trips up many developers is that the awakeFromNib message for the initial view controller (the one you see when the application starts) is sent before the applicationDidFinishLaunching: message. If you have a problem with that, do what you need to do in ViewDidLoad.