NSTimer不能从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];
希望能帮助到你