Search code examples
ioscallbackcontainersappearanceviewdidappear

iOS - Is it possible for a container view to receive appearance methods/callbacks instead of the child views?


I am trying to create a global call for all child views of a container view when the view appears.

Situation:

  1. App is sent to background. In AppDelegate a User Default gets set to TRUE.
  2. App is re-opened by user. Container view checks (in viewDidAppear callback) if user default is TRUE, if it is, it opens a modal view requiring a passcode to be entered.

I know I can add the method to open the passcode modal to the child controllers directly, but because there are so many and they may change in the app's lifetime, I was hoping to make a global call directly from the container view.

How can I get the container view to respond to the appearance callback methods (i.e. viewWillAppear, viewDidAppear, etc.)?


Solution

  • Solved it with a notification using 'UIApplicationDidBecomeActiveNotification':

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(applicationDidBecomeActive)
                                                 name:UIApplicationDidBecomeActiveNotification object:nil];