0

Hey I have an initial screen that comes up when the app is launched the first time or when edit button is clicked, I will be taking a target date from the user using a date picker.
How can I then do a countdown on the home screen to this given date??
Please help!

Alison
  • 13
  • 1
  • 5

3 Answers3

0

Add NSTimer and use this two variables NSTimeInterval start = [[NSDate date] timeIntervalSince1970]; NSTimeInterval end = [selectedDate timeIntervalSince1970];

NeverBe
  • 5,213
  • 2
  • 25
  • 39
0

You could use timeIntervalSince like this;

NSDate *chosenDate;

// Time interval between future date and todays date
NSTimeInterval *intervalInSeconds = [chosenDate timeIntervalSinceDate:[NSDate Date]];

Then you convert it to the units of your choice like this;

How can I calculate the difference between two dates?

Community
  • 1
  • 1
Jonathan King
  • 1,528
  • 14
  • 25
0

It sounds like are asking asking about how to share a property between screens. There are a couple approaches to this.

  1. Put the date property in your appDelegate
  2. Give your initial screen a reference to the home screen
  3. Give your home screen a reference to the initial screen
  4. Create a singleton that manages data for you.
Dancreek
  • 9,524
  • 1
  • 31
  • 34