NSTimer 在共享类中因 EXC_BAD_ACCESS 崩溃

发布于 2024-09-28 20:25:49 字数 565 浏览 0 评论 0原文

我有一个在共享类中运行的 NSTimer。 + (GlobalClass *)sharedInstance;

基本上它运行一次,第二次运行时,它就杀死了整个应用程序。

这就是我正在做的 NSTimer

myTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
                                             target:self
                                           selector:@selector(moveMe)
                                           userInfo:nil
                                            repeats:YES];

方法 moveMe 目前只是一个空方法。所以它不应该是 moveMe 中发生的事情。

有人经历过这个吗?

I have an NSTimer running in a shared class. + (GlobalClass *)sharedInstance;

Basically it runs once, and the second time it runs, it just killed the whole app.

This is how I'm doing the NSTimer

myTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
                                             target:self
                                           selector:@selector(moveMe)
                                           userInfo:nil
                                            repeats:YES];

method moveMe is just an empty method for now. So it shouldn't be something that's happening within moveMe.

Has anyone experienced this?

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

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

发布评论

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

评论(1

坠似风落 2024-10-05 20:25:49

您的选择器名称中似乎缺少冒号。 NSTimer 的选择器采用 NSTimer 作为参数。创建计时器的代码应如下所示:

myTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
                                           target:self
                                         selector:@selector(moveMe:)
                                         userInfo:nil
                                          repeats:NO];

注意 moveMe 后面的冒号。然后你的方法应该看起来像这样:

- (void)moveMe:(NSTimer *)aTimer {
    // Code
}

It looks like you're missing the colon in your selector name. The selector for NSTimer takes an NSTimer as an argument. Your code that creates the timer should look like this:

myTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
                                           target:self
                                         selector:@selector(moveMe:)
                                         userInfo:nil
                                          repeats:NO];

Note the colon after moveMe. Your method should then look something like this:

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