简体   繁体   English

计时器无效

[英]Timer invalidate

这句话的意思是什么?

NSTimer *timer ,[timer invalidate]

It's an objective C timer statement that cancels a running timer. 这是一个客观的C计时器语句,可取消正在运行的计时器。

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];

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. 似乎您是在创建NSTimer实例而不定义它,然后出于某种原因而在同一行中停止了该计时器。 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. 浪费内存分配资源,除非您打算在以后使用计时器,在这种情况下,您应该随后触发计时器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM