In my opinion, just try this code below,
Take one NSInteger in your .h file for example
NSInteger intTmp;
then in the .m file call the NSTimer method, for example,
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(testMethod:) userInfo:nil repeats:YES];
And write a selector like this
-(void)testMethod:(NSTimer *)pTmpTimer { intTmp += 1; if(intTmp <= 20) { [self performSelector:@selector( move1) withObject:nil afterDelay:0.0]; [self performSelector:@selector( move2) withObject:nil afterDelay:0.2]; [self performSelector:@selector( move3) withObject:nil afterDelay:0.4]; [self performSelector:@selector( move1) withObject:nil afterDelay:0.8]; [self performSelector:@selector( move2) withObject:nil afterDelay:0.10]; [self performSelector:@selector( move3) withObject:nil afterDelay:0.12]; } else { [pTmpTimer invalidate]; intTmp = 0; } }
From the above code, testMethod will ring 20 times, and according to your requirement, your code will repeat 20 times.
Hope this works for you.
Happy coding.
source share