Reputation: 1186
I am very new in Iphone Development. I have an issue . I am using a NSTimer which update a UiLabel in every second. now i have two problem :
can anyone help me.
code which i am using :
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES];
-(void) updateCountdown
{
secondsLeft--;
//nits testing
if(secondsLeft == 1)
{
[self.view addSubview:recipePage6View.view];
}
if (secondsLeft<0)
{
[timer invalidate];
timer=nil;
lblDisplayTimer.text =@"00:00:00";
}
else
{
hours = secondsLeft / 3600;
minutes = (secondsLeft % 3600) / 60;
seconds = (secondsLeft %3600) % 60;
lblDisplayTimer.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
//lblDisplayTimer.text = [NSString stringWithFormat:@"%02d:%02d",minutes,seconds];
}
}
Upvotes: 1
Views: 1337
Reputation: 1389
You need to set up a special background timer task and not have an NSTimer on the main run loop which gets suspended in background. The documentation on how to do this is here
Upvotes: 4