NSTimer没有从AppDelegate中重复 [英] NSTimer not repeating from AppDelegate

查看:61
本文介绍了NSTimer没有从AppDelegate中重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么将其放置在appDidFinishLaunching中时不会重复?

why would this not repeat when place in appDidFinishLaunching?

self.ti = [NSTimer timerWithTimeInterval:10. target:self selector:@selector(bounce:) userInfo:nil repeats:YES];
[self.ti fire];

非常感谢

朱尔斯

推荐答案

我认为您的 bounce 签名错误.应该是

I think your bounce has a wrong signature. It should be

- (void)bounce:(NSTimer*)theTimer {
    NSLog(@"Here...");
}

您应该使用 selector(bounce:)安排此方法.您还应该调用 scheduledTimerWithTimeInterval 而不是 timerWithTimeInterval :

You should be using selector(bounce:) to schedule this method. You should also be calling scheduledTimerWithTimeInterval instead of timerWithTimeInterval:

self.ti = [NSTimer
    scheduledTimerWithTimeInterval:10.
                            target:self
                          selector:@selector(bounce:)
                          userInfo:nil
                           repeats:YES];

这篇关于NSTimer没有从AppDelegate中重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆