2

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

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

非常感谢

朱尔斯

4

2 回答 2

4

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

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

希望能帮助到你

于 2012-05-11T14:46:35.103 回答
4

我认为您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];
于 2012-05-11T14:42:22.953 回答