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];
The problem is that
targetis nil.What this timer does is every 7 seconds it calls
[nil foo], which does nothing.If you want to call the method
fooon the object that creates the timer, usetarget:self