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 :
- when my app goes in background and after it when i open app . app goes hangs.
- if i goes next or back on other ui screen then wen i comes on timer screen then my label again shows 0.
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];
}
}