I was just wandering If there is a simplier method to repeat the codes below for 20 seconds. If there is, how?
[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];
According to my opinion Just try this code below,
Take one NSInteger in your Controller's .h file, like this,
NSInteger intTmp;
then in .m file Call NSTimer method like this,
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(testMethod:) userInfo:nil repeats:YES];
And write 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 above code, testMethod will call 20 times and according to your requirement your code will repeat 20 times..
Hope It works for you.
Happy coding..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With