0

I've got @property NSDate instance and it get time in method - (void)applicationWillResignActive:(UIApplication *)application .

I've got ViewController and SecondController connected to Storyboard so in code in AppDelegate Implementation block i haven't any ViewController and SecondViewController instance. Method - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions only returns YES.

The problem is: I must to pass time from @property NSDate instance to SecondViewController which is displayed when application is become active, but i don't know how can i check if SecondViewController is displayed after application comes from background.

I know that i can use AppDelegate:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

And then get his NSDate @property, but how can i check when i have to get this data?

Which method of ViewController should i use?

Tomasz Szulc
  • 4,217
  • 4
  • 43
  • 79

1 Answers1

1

If you want SecondViewController's view to always have the current date value when it appears, get it from the data model (in this case AppDelegate) during viewWillAppear:.

Phillip Mills
  • 30,888
  • 4
  • 42
  • 57
  • problem is when i add `NSLog` in `SecondViewController` `viewWillAppar:` method i see any results.. This view is displayed when i click home and when i back is displayed too so `viewWillAppear` isn't called. – Tomasz Szulc Sep 12 '12 at 21:35
  • That's odd. What causes `SecondViewController` to be used? If it's a segue, what triggers the segue...code or some user action? – Phillip Mills Sep 12 '12 at 21:46
  • Yeah, i've got `ViewController` and `UITableView`. When i select `Cell` then by `Modal Segue` application display `SecondViewController`. And when this `SecondViewController` is displayed i want to lock iDevice, but when i do this then `AppDelegate` get date when i do this and when application become active i want to get data from `AppDelegate` and edit it in `SecondViewController`. Any `viewWill...` or `viewDid...` isn't working with `SecondViewController` : / – Tomasz Szulc Sep 12 '12 at 21:50
  • 1
    In that case, have your `SecondViewController` listen for the `UIApplicationDidBecomeActiveNotification` notification. You should get called when the device is unlocked. – Phillip Mills Sep 12 '12 at 22:04