8

I have a method -(void)foo that I want to call once in viewDidAppear, then I want it to repeat every n seconds, where n is some integer. How can I do this?

I tried this, but it's not repeating:

[NSTimer scheduledTimerWithTimeInterval:7.0 target:nil selector:@selector(foo) userInfo:nil repeats:YES];
Snowman
  • 31,411
  • 46
  • 180
  • 303

1 Answers1

17

The problem is that target is nil.

What this timer does is every 7 seconds it calls [nil foo], which does nothing.

If you want to call the method foo on the object that creates the timer, use target:self

cobbal
  • 69,903
  • 20
  • 143
  • 156