定时器无效

发布于 2024-08-23 03:43:59 字数 78 浏览 1 评论 0原文

这句话的含义是什么?

NSTimer *timer ,[timer invalidate]

What is the meaning of this statement given?

NSTimer *timer ,[timer invalidate]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

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

评论(2

娜些时光,永不杰束 2024-08-30 03:43:59

这是一个客观的 C 计时器语句,用于取消正在运行的计时器。

一般情况下会表示为:

NSTimer* myTimer = [NSTimer timerWithTimeInterval:1.0 target:self
                                             selector:@selector(calculateTLE) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:myTimer forMode: NSDefaultRunLoopMode];

..

[myTimer invalidate];

It's an objective C timer statement that cancels a running timer.

Normally it would be expressed as:

NSTimer* myTimer = [NSTimer timerWithTimeInterval:1.0 target:self
                                             selector:@selector(calculateTLE) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop] addTimer:myTimer forMode: NSDefaultRunLoopMode];

..

[myTimer invalidate];
可是我不能没有你 2024-08-30 03:43:59

看起来好像您正在创建 NSTimer 的实例而不定义它,然后在同一行中出于某种原因停止同一个计时器。浪费内存分配资源,除非您打算稍后使用计时器,在这种情况下您应该触发计时器。

It looks as though you're creating an instance of NSTimer without defining it, and then in the same line for whatever reason stopping that same timer. Waste of memory allocation resources, unless you're planning to use the timer at a later time, in which case you should trigger the timer then.

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