2

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

Vaibhav Saran
  • 12,848
  • 3
  • 65
  • 75
Jules
  • 660
  • 8
  • 29
  • What is the code in 'bounce'? Also, how are you setting up 'ti'. – WhoaItsAFactorial May 11 '12 at 14:38
  • in bounce i am simply logging at the moment to see if it is being called, ti is a property in my header (strong, nonatomic) and synthesized. It appears the code isnt even firing once let alone repeating? Many thanks again – Jules May 11 '12 at 14:39

2 Answers2

4

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];
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
4

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

Novarg
  • 7,390
  • 3
  • 38
  • 74