一旦 NSTimer 在 objective c 中停止关闭我的视图控制器

Once NSTimer stop dismiss my view controller in objective c

我正在使用 NSTimer,

timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: YES];

然后是我的 60 秒倒计时程序

-(void) updateCountdown {
    int hours, minutes, seconds;

   secondsLeft++;
    hours = secondsLeft / 3600;
    minutes = (secondsLeft % 3600) / 60;
    seconds = (secondsLeft %3600) % 60;


    time.text = [NSString stringWithFormat:@"%02d",  seconds];

}

我的问题是在 60 秒后关闭我的倒计时视图控制器页面..任何人都可以帮助我

如果 repeats: YES]; 检查你的 seconds 达到或大于 60,使你的计时器无效并关闭你的 VC

if (seconds >60)
{
[timer invalidate];
[self dismissViewControllerAnimated:YES completion:nil];
}

否则使用 repeats: NO];

调用您的计时器一次
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(updateCountdown) userInfo:nil repeats: NO];

并像

那样调用函数
-(void) updateCountdown {
   [timer invalidate];
  [self dismissViewControllerAnimated:YES completion:nil];

}
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
}