I feel I am missing a trick here...
I just want to call viewDidLoad or viewDidAppear on the current active view controller when applicationDidBecomeActive gets called, so I can reset some animations or whatever, when the app is started up again from the background. Some of my views don't care, but others really need to know.
I am using Storyboards and my app delegate file has the standard functions - but all with EMPTY bodies. For example, didFinishLaunchingWithOptions just returns YES and does nothing else. Storyboard automagically does everything I guess.
So how can I talk to the current view controller from my rather blank, information free, app delegate?
applicationWillEnterForeground is called: when app is relaunched(comes from background to foreground) This method is not invoked when app starts for the first time i.e when applicationDidFinishLaunch is called but only when comes from background applicationDidBecomeActive.
viewWillAppear: This method is called every time before the view is visible to and before any animation is configured. In this method view has bound but orientation is not set yet.
From the Library, add a button to the first View Controller and name the button, for example: Show Second View . Select the button, press and hold the Control key on the keyboard and drag from the button to the second View Controller.
Instead of sending a notification from your app delegate, the OS sends a notification automatically that you can observe:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initSongInfo) name:UIApplicationDidBecomeActiveNotification object:nil];
and of course make sure to stop observing sometime before or inside your dealloc method, by calling:
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidBecomeActiveNotification object:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With