Tomasz Szulc
Tomasz Szulc

Reputation: 4235

How to pass data between AppDelegate and SecondViewController

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?

Upvotes: 0

Views: 340

Answers (1)

Phillip Mills
Phillip Mills

Reputation: 31026

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:.

Upvotes: 1

Related Questions