Reputation: 167
I am using NSTimer
,
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES];
then my 60 second count down timer program
-(void) updateCountdown {
int hours, minutes, seconds;
secondsLeft++;
hours = secondsLeft / 3600;
minutes = (secondsLeft % 3600) / 60;
seconds = (secondsLeft %3600) % 60;
time.text = [NSString stringWithFormat:@"%02d", seconds];
}
my question is after 60 second dismiss my count down view controller page .. anyone can help me
Upvotes: 2
Views: 562
Reputation: 82759
if repeats: YES];
check like your seconds
reaches or greater than 60
, invalidate your timer and dismiss your VC
if (seconds >60)
{
[timer invalidate];
[self dismissViewControllerAnimated:YES completion:nil];
}
else call your timer once using repeats: NO];
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: NO];
and call the function like
-(void) updateCountdown {
[timer invalidate];
[self dismissViewControllerAnimated:YES completion:nil];
}
Upvotes: 7
Reputation: 2207
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown:) userInfo:nil repeats: NO]; // set No
-(void) updateCountdown:(NSTimer *)timer
{
[timer invalidate];
// dismiss your controller
}
Upvotes: 2