gpt4 book ai didi

ios - 一旦 NSTimer 停止在 objective-c 中关闭我的 View Controller

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:57:26 26 4
gpt4 key购买 nike

我正在使用 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 秒后关闭我的倒计时 View Controller 页面..任何人都可以帮助我

最佳答案

如果 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];

}

关于ios - 一旦 NSTimer 停止在 objective-c 中关闭我的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43047524/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com