Reputation: 741
ok, so i have an array of strings of several methods that i want to run each in 2 second intervals. i can't figure out how to do this tho, I've tried using a forward loop however like this:
SEL methods;
NSTimer *timerBetweenMethods;
for (int i=0;i<[self.arrayOfStringsOfMethods count];i++{
methods=NSSelectorFromString([self.arrayOfStringsOfMethods objectAtIndex:i]);
timeBetweenMethods=[NSSTimer scheduledTimerWithInterval:2 target:self selector:methods userInfo:nil repeats:NO];
}
so say i have 10 methods in that array, what i want to happen is for the first method to run, then 2 seconds after the second, then 2 seconds after the third, etc... until the 10th for a total of 20 seconds to do this. However, what actually happens is after 2 seconds all the methods run at the same time, and i think this is because this forward loop is just quickly setting the timer, but not waiting until the timer does its method before looping again, which i guess makes sense, but how can i get my program to do what i want? o, and btw I just learned about NSTimer today so I'm very new to it.
Upvotes: 0
Views: 215
Reputation: 299605
You're scheduling them all for the same time, as you note. Set your interval to 2*(i+1)
rather than just 2.
Upvotes: 2