Method invocation with timer
0 Comments 17th APR 2009 | Posted by Ivan Kalaica in iPhone development

Method invocation with timer is something every developer sometime needs. First you make an instance of NSInvocation class and you add invocationWithMethodSignature.
invocationWithMethodSignature consists of method selector (which method your invocation will trigger) and target (which object is target). Next you make instance of NSTimer class to define repeat interval. See example below.
- (void) viewDidLoad {
NSInvocation *updateDisplayInvocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector: @selector (myMethod)]];
[updateDisplayInvocation setSelector: @selector (myMethod)];
[updateDisplayInvocation setTarget: self];
NSTimer *audioDisplayUpdateTimer;
audioDisplayUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 invocation:updateDisplayInvocation repeats:YES];
[super viewDidLoad];
}
- (void) myMethod {
NSLog(@"Method execution");
}
And that is it!

















