objective-c – 如何在使NSTimer失效后“验证”?

objective-c – 如何在使NSTimer失效后“验证”?,第1张

概述所以基本上,我有这个定时器,当它收到一个密钥事件时应该重复,当用户释放密钥时,它将无效。但是,即使通过调用NSRunLoop中的addTimer:forMode,我无法“验证”定时器。有人知道为什么会发生这种情况吗?谢谢。 您不能使用无效定时器。 从苹果文档: Once scheduled on a run loop, the timer fires at the specified interv 所以基本上,我有这个定时器,当它收到一个密钥事件时应该重复,当用户释放密钥时,它将无效。但是,即使通过调用NSRunLoop中的addTimer:forMode,我无法“验证”定时器。有人知道为什么会发生这种情况吗?谢谢。解决方法 您不能使用无效定时器。

从苹果文档:

Once scheduled on a run loop,the timer fires at the specifIEd interval until it is invalIDated. A non-repeating timer invalIDates itself immediately after it fires. However,for a repeating timer,you must invalIDate the timer object yourself by calling its invalIDate method. Calling this method requests the removal of the timer from the current run loop; as a result,you should always call the invalIDate method from the same thread on which the timer was installed. InvalIDating the timer immediately disables it so that it no longer affects the run loop. The run loop then removes and releases the timer,either just before the invalIDate method returns or at some later point. Once invalIDated,timer objects cannot be reused.

总结

以上是内存溢出为你收集整理的objective-c – 如何在使NSTimer失效后“验证”?全部内容,希望文章能够帮你解决objective-c – 如何在使NSTimer失效后“验证”?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1036796.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存