Hello friends I am new to iOS development. I have one issue related to NSTimer. I am using NSTimer in my view controller.
Timer starts decreasing value on the UIButton event. After calling timer when i goes to another view controller. Then timer decreasing value that it's work fine. But when i come back to timer view then timer stops updating value means timer don't call it's @selector() method. How can i call value updating method when i come back to timer view ?
My code is as follows:
-(IBAction)btnStrDecPressed:(id)sender
{
countDownlabel.text = [NSString stringWithFormat:@"%@:%@:%@", pickhour, pickmins, picksecs];
secondsLeft=[pickhour intValue] * 3600;
secondsLeft=secondsLeft + [pickmins intValue] * 60;
secondsLeft=secondsLeft + [picksecs intValue];
appdel.LeftSeconds=secondsLeft;
NSLog(@"%d",appdel.LeftSeconds);
if(timer==nil)
{
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES];
}
}
-(void)updateCountdown
{
int hours, minutes, seconds;
hours = appdel.LeftSeconds / 3600;
minutes = (appdel.LeftSeconds % 3600) / 60;
seconds = (appdel.LeftSeconds %3600) % 60;
appdel.LeftSeconds--;
countDownlabel.text = [NSString stringWithFormat:@"%02d:%02d:%02d", hours, minutes, seconds];
if (appdel.LeftSeconds==0)
{
[[[UIAlertView alloc] initWithTitle:@"Restaurant" message:@"Timer Completed" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
[timer invalidate];
}
}
Where pickhour,pickmins,picksecs are values getting from UIPickerview.