我一直在成功使用NSTimer,但现在遇到了麻烦。毫无疑问有些愚蠢。欣赏另一组眼睛。运行调试器,我看到applicationDidFinishLaunching被调用,但是从不调用触发器。NStimer - 我在这里做错了什么?
-(void) trigger:(NSTimer *) theTimer{
NSLog(@"timer fired");
}
- (void)applicationDidFinishLaunching:(UIApplication *)application {
nst = [NSTimer timerWithTimeInterval:1.0 target:self selector:@selector(trigger) userInfo:nil repeats:YES];
[window makeKeyAndVisible];
}
以及以下所述,如果不使用垃圾回收,您必须保留计时器。 – 2010-02-07 22:11:52
如果您添加计时器来运行循环,则不需要保留它,我认为运行循环会保留它。 – Jaanus 2010-02-07 22:48:35
谢谢大家捕捉方法签名错误。另一件让我恼火的事情是我使用了scheduledTimerWithInterval,它不需要手动添加到运行循环中。在这种情况下,我忘记了scheduledTimer部分。 – morgancodes 2010-02-07 23:31:17