0

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.)?

JimmyJammed
  • 9,598
  • 19
  • 79
  • 146
  • What about just handling this in the app delegate? You can just switch the root view controller to the login view. – Aaron Brager May 27 '14 at 22:17
  • Side note: you may want to use the keychain instead of `NSUserDefaults`, since the latter is insecure and easily modified by a user. – Aaron Brager May 27 '14 at 22:18
  • 1
    You could also register for application lifetime events like `UIApplicationDidBecomeActive` and handle them from any object. Then just present from whatever the topmost view controller happens to be – jaggedcow May 27 '14 at 23:08
  • AaronBrager - Yes, I will be updating to use keychain. However, I can't use AppDelegate as I don't want to switch the root view. I want the passcode view to appear on top of whatever the current view is, so they don't get popped back to the start of the app. jaggedcow - I didn't realize I could use those methods directly in views, thought they only applied to the AppDelegate. I will try those tonight and report back. Thanks for the suggestions guys! – JimmyJammed May 28 '14 at 17:51

1 Answers1

0

Solved it with a notification using 'UIApplicationDidBecomeActiveNotification':

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(applicationDidBecomeActive)
                                             name:UIApplicationDidBecomeActiveNotification object:nil];
JimmyJammed
  • 9,598
  • 19
  • 79
  • 146