-
Notifications
You must be signed in to change notification settings - Fork 15
Timers
Timothy Lee edited this page Jul 29, 2014
·
2 revisions
Configure a simple repeating timer as in the snippet below. After calling the scheduledTimerWithTimeInterval method, the timer is immediately scheduled and will call the selector at the time interval.
Declare and implement the method that you want to be called when the timer fires. You can name this method whatever you want, just pass the name of the method to the timer when you create it.
@interface MainViewController()
- (void)onTimer;
@end
For example, to schedule the onTimer
method to be called every 5 seconds, use the code below. If you want the timer to fire every 100ms, just use 0.1 for the time interval.
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(onTimer) userInfo:nil repeats:YES];