在定义的秒数后调用函数而不使用计时器

发布于 2024-11-28 05:11:56 字数 339 浏览 3 评论 0原文

我使用计时器在 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

没︽人懂的悲伤 2024-12-05 05:11:56

我认为有一种方法可以完成此任务,

[self performSelector:@selector(yourMethodName) withObject:[NSArray arrayWithObjects:firstArgument,secondeArgument,nil] afterDelay:180];

如果该方法中没有参数,则可以像这样使用 nil 代替数组。

I think there is a method to do this task, here use it like this

[self performSelector:@selector(yourMethodName) withObject:[NSArray arrayWithObjects:firstArgument,secondeArgument,nil] afterDelay:180];

use nil in place of array if you have no argument in that method.

烂人 2024-12-05 05:11:56

您可以使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文