有没有办法消除 NSTimer
上的初始延迟?以下代码用于我的计时器,一切正常。
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
但是,该方法在前 5 秒内没有运行。我希望我的方法 (updateTime
) 在应用程序打开时从 00:00:00 开始在以下时间线上运行。
- 00:00:00 - 运行方法
- 00:00:05 - 运行方法
- 00:00:10 - 运行方法
目前,它只做:
- 00:00:05 - 运行方法
- 00:00:10 - 运行方法
最佳答案
您无法在计时器的时间间隔结束之前触发计时器,但您可以这样做:
NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
[self updateTime];
关于ios - 没有初始延迟的 NSTimer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28507113/