如何立即触发NSTimer? [英] How to trigger NSTimer right away?
本文介绍了如何立即触发NSTimer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在应用启动时调用方法,然后每隔5秒调用相同的方法。
我的代码很简单:
//调用方法马上
[self updatestuff:nil]
//设置一个计时器,这样每5秒调用一次方法
timer = [NSTimer scheduledTimerWithTimeInterval:5
target :self
选择器:@selector(updatestuff :)
userInfo:nil
重复:是];
计时器是否有选项,因此它会立即触发,然后每5秒触发一次?
解决方案
NSTimer
的 -fire
, [计时器开火];
是您正在寻找的。 p>
这将立即触发打电话给计时器解除时间延迟。
I need to call a method when my app starts and then call the same method every 5 seconds.
My code is pretty simple:
// Call the method right away
[self updatestuff:nil]
// Set up a timer so the method is called every 5 seconds
timer = [NSTimer scheduledTimerWithTimeInterval: 5
target: self
selector: @selector(updatestuff:)
userInfo: nil
repeats: YES];
Is there an option for the timer so it's trigger right away and then every 5 seconds ?
解决方案
NSTimer
's -fire
, [timer fire];
is what you're looking for.
That will fire/immediately call the timer dismissing the time delay.
这篇关于如何立即触发NSTimer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文