在定义的秒数后调用函数而不使用计时器
我使用计时器在 180 秒后调用一个函数。但计时器有时会以不同的方式运行,并在 180 秒内多次调用该函数。
请建议我如何在每 180 秒后调用一个函数,直到我在不使用计时器的情况下发布停止消息。
代码
if(!tmr_CallWebService)
{
tmr_CallWebService = [NSTimer ScheduledTimerWithTimeInterval:180 目标:ClassTracing 选择器:@selector(startLocationTracing) userInfo:nil 重复:YES];
}
提前致谢
I am calling a function after 180 seconds using timer. But the timer sometimes behaves in different manner and calls the function multiple times in 180 seconds.
please suggest me how to call a function after each 180 seconds untill I post stop message without using timer.
Code
if(!tmr_CallWebService)
{
tmr_CallWebService = [NSTimer scheduledTimerWithTimeInterval:180 target:ClassTracing selector:@selector(startLocationTracing) userInfo:nil repeats:YES];
}
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为有一种方法可以完成此任务,
如果该方法中没有参数,则可以像这样使用 nil 代替数组。
I think there is a method to do this task, here use it like this
use nil in place of array if you have no argument in that method.
您可以使用 NSObject 的
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
You can use
- (void)performSelector:(SEL)aSelector withObject:(id)anArgument afterDelay:(NSTimeInterval)delay
from NSObject