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 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With