Hey guys, Is it possible to call a function like Code: [self moveImage:image]; With a timer? I've tried Code: [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(moveImage:image) userInfo:nil repeats:YES]; and Code: [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector([self moveImage:image]) userInfo:nil repeats:YES]; But none succeeded. Is there a way to do this? Thanks.
You're missing a step. MoveImage shouldn't be in the timer call. You need to call a timer action, with MoveImage inside it. Something like this: Code: [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(TimerAction:) userInfo:nil repeats:YES]; -(void)TimerAction:(NSTimer*)pTimer { [self moveImage:image]; }
That's right, and if image is local to the method that fired the timer you'll need to pass it as the userInfo parameter when you create the timer. Then in TimerAction: it can be accessed by pTimer.userInfo. You might also want to look up performSelector:withObject:afterDelay: it does the same thing but the SDK deals with the timer instead of you For example: Code: [self performSelector:@selector(moveImage:) withObject:image afterDelay:0.05];