iPhone NSTimer 失效问题

发布于 2024-09-10 10:24:32 字数 539 浏览 5 评论 0原文

好吧,我知道我不久前问过类似的问题,但这是不同的。我现在有两个计时器,它们在各自按钮的 TouchDown 事件上启动。在 TouchUpInside 事件中,我有各自的代码告诉每个计时器 [pressTimer invalidate]pressTimer = nil。自从我添加第二个计时器以来现在发生的问题是,当触发选择器(从而释放按钮并触发 TouchUpInside 事件)时,应用程序崩溃并吐出 Not recognize [NSCFTimer -invalidate]或类似的东西。按钮正常工作,直到计时器触发,即使如此,直到我松开手指也没有崩溃。我认为发生的事情是 TouchUpInside 事件试图使无效/触发的计时器无效,因为它在计时器仍在运行时工作正常。我想知道为什么会发生这种情况,因为在我添加第二个计时器之前它从未发生过。我的临时修复方法是设置计时器的重复:YES 部分,这支持我的理论,即它不能使无效/触发的计时器无效。有什么建议吗?

*奖励:在相关说明中,我需要从人们那里获得多少次崩溃才能出现在 iTunes Connect 中?

Okay so I know I asked a similar question a while ago, but this is different. I now have two timers that go off on the TouchDown event of their respective buttons. On the TouchUpInside event I have respective code that tells each timer to [pressTimer invalidate] and pressTimer = nil. The problem that happens now since I added the second timer is that when the selector is triggered (thus releasing the button and triggering the TouchUpInside event) the app crashes and spits out an Not recognized [NSCFTimer -invalidate] or something like that. The buttons work normally, until the timer triggers, and even then no crash until I let up my finger. I think what's going on is that the TouchUpInside event is trying to invalidate an invalid/triggered timer, because it works fine while the timer is still running. I wonder why this is happening since it never happened before I added the second timer. My temporary fix is to set the repeating:YES portion of the timer, which supports my theory that it can't invalidate an invalid/triggered timer. Any suggestions?

*Bonus: On a related note, how many crashes do I need to get from people before they show up in iTunes Connect?

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

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

发布评论

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

评论(1

世俗缘 2024-09-17 10:24:32

一方面,pressTimer=nil 没有任何作用; nil 赋值仅在使用 setter 时,在 retained 属性上释放对象,即 self.timer = nil;。 (这实际上是这样的:[self setTimer:nil]!)

但即便如此,如果您错误引用自己并确实使用了 setter,则不需要释放 NSTimer 实例,它只需要invalidate即可。您的“引用类型”错误不应该发生。

至于你的理论:在这种情况下,你可以将 invalidate 读为 release - 你不能经常这样做......

手册指出需要从以下位置调用 invalidate与安装它的线程相同,除此之外,真的没有任何理由导致任何崩溃。

For one thing, the pressTimer=nil serves no purpose; nil assignment only releases objects when using a setter, on a retained property, i.e. self.timer = nil;. (this actually does: [self setTimer:nil]!)

But even then, if you misquoted yourself and did use a setter, an NSTimer instance need not be released, it only needs to be invalidated. Your "kind of quoted" error should not happen.

As for you theory: you may read invalidate as release in this context - you can't do it too often...

The manual states that invalidate needs to be called from the same thread where it was installed, beyond that there's really no reason for anything to crash.

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