Just keep track of the number of cycles and keep a reference to the timer object. Then just invalidate it when you have done enough.
// ivars int loopCount; NSTimer *myTimer; // Method that calls your timer. - (void)doStuff { loopCount++; if (loopCount >= 10) { [myTimer invalidate]; myTimer = nil; } else { //do my stuff here... } } // Method that kicks it all off - (IBAction)startDoingStuff { myTimer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(doStuff) userInfo:nil repeats:YES]; }
Alex wayne
source share