繁体   English   中英

NSTimer不会从AppDelegate重复

[英]NSTimer not repeating from AppDelegate

放在appDidFinishLaunching中时为什么不重复?

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

非常感谢

儒勒

我认为你的bounce有一个错误的签名。 它应该是

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

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

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

我不确定它是否有用,但尝试使用scheduledTimerWithTimeInterval方法。 一个例子:

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

希望能帮助到你

暂无
暂无

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

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