Possible Duplicate:
How to make a periodic call to a method in objective c?
I am making an app where when the user touches the screen, the following method is called:
- (void)explode:(int)x
The user only has to touch the screen once, but I want the method to be called repeatedly every 0.1 seconds for 100 times, and then it should stop being called.
Is there a way of setting up a ‘temporary’ timer like this on a method where an integer is being passed?
You could pass a counter and the ‘x’ as into the timer’s userInfo. Try this:
Create the timer in the method that’s catching the touch event and pass a counter and the int ‘x’ into the userInfo:
Create the timer method, check the userInfo’s number count, and invalidate the timer after 100 times:
Please also see the Apple docs on
NSTimer:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nstimer_Class/Reference/NSTimer.html