It seems that UIApplication
is dispatching a message to the active view controller.
But how does your View Controller instance get these messages?
The message is forwarded to the first view controller whose view has been added to the UIWindow
instance.
This boils down to 3 basic scenarios:
The ViewController whose view is
added directly to the UIWindow
instance (single view app)
The navigation Controller in a
Navigation based app, then the
navigation controller forwards the
message to the active views view
controller.
The tab bar Controller in a tab bar
based app, then the tab bar
controller forwards the message to
the active views view controller (or
the active navigation controller).
The problem you will have, is if you build an app with multiple views, but DO NOT use a Navigation controller or Tab Bar controller. If you swap views in and out of the UIWindow
instance manually, you will not receive these messages reliably.
This is similar to posts like this one:
iPhone viewWillAppear not firing
Just use Apple's conventions for multiple views and you be fine. Hope this saves some one an hour or two
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…