Cocoa touch 如何重置计时器?
我有一个应用程序,每3秒钟触发一个事件,该事件会进入我的服务器并获取信息。如果在计时器上次启动和随后启动之间发生事件,我想重置计时器倒计时 因此,基本上,如果我的其他事件在2.5秒时触发,并且计时器设置为在0.5秒后触发,我想将计时器重置回3秒。我怎样才能做到这一点 我宣布计时器为:Cocoa touch 如何重置计时器?,cocoa-touch,Cocoa Touch,我有一个应用程序,每3秒钟触发一个事件,该事件会进入我的服务器并获取信息。如果在计时器上次启动和随后启动之间发生事件,我想重置计时器倒计时 因此,基本上,如果我的其他事件在2.5秒时触发,并且计时器设置为在0.5秒后触发,我想将计时器重置回3秒。我怎样才能做到这一点 我宣布计时器为: _timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target: self
_timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target: self
selector: @selector(getUpdates)
userInfo:nil
repeats: YES];
和psuedo:
-(void) anEventHappened
{
// I got something from the server, I don't need to query it. Reset timer here.
}
-(void) getUpdates
{
// I received no reset, I should check for an update.
}
这行吗
[_timer invalidate];
_timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target: self
selector: @selector(getUpdates)
userInfo:nil
repeats: YES];