NSTimer 问题:2 秒后连续调用 NStimer ---
我使用简单的代码来启动一个重复计时器,该计时器每 30 秒调用一个方法。
[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(refresh) userInfo:nil repeats:YES];
它可以正常启动,但一段时间后,它会每隔 2 或 3 秒随机调用“刷新”方法。我没有修改计时器或代码中的任何其他地方。猜猜可能出了什么问题......
谢谢!
I am using simple code to start a repetitive timer which calls a method after every 30 seconds.
[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(refresh) userInfo:nil repeats:YES];
It starts properly but after some time it calls the 'refresh' method after every 2 or 3 seconds randomly. I am not modifying the timer or anything anywhere else in the code . Any guess what could be possibly going wrong .....
Thank You!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码是否有可能运行多次,从而设置一个计时器的多个实例,超时时间为 30 秒,并在不同的时间触发?
如果情况并非如此,您正在执行的某些处理是否可能会阻塞运行循环并导致计时器事件排队?
我建议检查这些可能性。
Is it possible that this code is being run more than once, thus setting up multiple instance of a timer with a 30 second timeout, all firing at different times?
If that isn't the case, is it possible that some of the processing you're doing is perhaps blocking the run loop and causing the timer events to queue up?
I would suggest checking those possibilities.