NSTimer not repeating from AppDelegate

…衆ロ難τιáo~ 提交于 2019-12-10 23:53:08

问题


why would this not repeat when place in appDidFinishLaunching?

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

many thanks

Jules


回答1:


I think your bounce has a wrong signature. It should be

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

You should be using selector(bounce:) to schedule this method. You should also be calling scheduledTimerWithTimeInterval instead of timerWithTimeInterval:

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



回答2:


I'm not sure if it will help, but try using scheduledTimerWithTimeInterval method. An example:

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

Hope it helps



来源:https://stackoverflow.com/questions/10553480/nstimer-not-repeating-from-appdelegate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!