简体   繁体   English

NSTimer不会从AppDelegate重复

[英]NSTimer not repeating from AppDelegate

why would this not repeat when place in appDidFinishLaunching? 放在appDidFinishLaunching中时为什么不重复?

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

many thanks 非常感谢

Jules 儒勒

I think your bounce has a wrong signature. 我认为你的bounce有一个错误的签名。 It should be 它应该是

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

You should be using selector(bounce:) to schedule this method. 您应该使用selector(bounce:)来安排此方法。 You should also be calling scheduledTimerWithTimeInterval instead of timerWithTimeInterval : 您还应该调用scheduledTimerWithTimeInterval而不是timerWithTimeInterval

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

I'm not sure if it will help, but try using scheduledTimerWithTimeInterval method. 我不确定它是否有用,但尝试使用scheduledTimerWithTimeInterval方法。 An example: 一个例子:

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

Hope it helps 希望能帮助到你

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

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