I’m trying to update a UILabel that is counting down from the users birthdate to a later date. I’m trying to update the label so they can see it counting down but can’t seem to get it working. Advice is appreciated!
Here’s where I make the timer:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeFormatted:) userInfo:nil repeats:NO];
}
and here is where I get the actual count down information…
- (NSString *)timeFormatted:(int)totalSeconds
{
NSTimeInterval theTimeInterval = [self numberOfSecondsToLive];
NSCalendar *sysCalendar = [NSCalendar currentCalendar];
NSDate *date1 = [[NSDate alloc] init];
NSDate *date2 = [[NSDate alloc] initWithTimeInterval:theTimeInterval sinceDate:date1];
unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:date1 toDate:date2 options:0];
_numberofSeconds.text = [NSString stringWithFormat:@" %dyears:%dMonths:%ddays:%dhour:%dminutes:%dseconds",[conversionInfo year],[conversionInfo month], [conversionInfo day], [conversionInfo hour], [conversionInfo minute], [conversionInfo second]];
[date1 release];
[date2 release];
}
What happens is that it does show the correct countdown information, but it doesn’t update it.
Thank you in advance!
You started the timer with
repeats:NOyou want that to berepeats:YESto have the timer repeat.