-1

I have one timer firing to go to a void statement. Which has another timer in it. I want to pause the one thats firing or going off then resume it.

movement3 = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(jone) userInfo:nil repeats:NO];


- (void)jone{

[jumperguy setImage:[UIImage imageNamed:@"jumperguy_a_a3.png"]];

movement4 = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(jtwo) userInfo:nil repeats:NO];
}
  • @Lyndsey Scott I tried implementing this before it didn't work out for me. Could be doing something wrong. I got a few errors. – Tyler Schoenau Jan 25 '15 at 21:54
  • Please post your exact issue and real code as your comments indicate you are doing something different from the question you have posted. – Robotic Cat Jan 25 '15 at 22:22
  • It is impossible to pause or resume a timer, see the question yours was marked a duplicate of. – Abhi Beckert Jan 26 '15 at 02:35

1 Answers1

0

You can only invalidate an NSTimer object to stop it. You can have two methods such as:

-(void) pauseTimer:(NSTimer *) timer {
    [timer invalidate];
    timer = nil;
}
-(void) resumeTimer:(NSTimer *) timer {
    timer = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(jone) userInfo:nil repeats:NO];
}
Armin
  • 1,150
  • 8
  • 24
  • I want to check which timer is running so I can invalidate it then start the timer up again. Like above I said I have multiple timers firing. So when one timer is done then it goes to another timer which is in a void statement and so on. – Tyler Schoenau Jan 25 '15 at 22:05
  • I have a hard time understanding what you're trying to do. Could you please give us an example scenario including your other timers? The 1 line of code you have in your question is not even a repeating timer! It'll run once, and that's it. What do you mean by "the current timer thats running" ?! – Armin Jan 25 '15 at 22:19
  • For an example I have multiple timers firing to set a image thats in each timer and I want to stop the timer so it stops on the current image it is on. Then resume the timer so the timer can move on doing its thing. – Tyler Schoenau Jan 25 '15 at 22:39
  • @TylerSchoenau you need to either update your question with more descriptive explanations and the complete code you're using, or find a new way to achieve what you're trying to do. I still don't understand what you're trying to achieve here. "I have multiple timers firing to set a image thats in each timer" makes no sense to me. How can you have an "image thats in each timer" ? Are you talking about a different NSTimer object or something else? – Armin Jan 25 '15 at 23:22
  • Yeah the different images are in different NSTimers. – Tyler Schoenau Jan 26 '15 at 00:58
  • Tyler, you can't have images "in" NSTimers man! It just doesn't make sense. Could you please just copy paste your code so I can see what you're talking about? – Armin Jan 26 '15 at 01:16
  • movement3 = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(jone) userInfo:nil repeats:NO]; - (void)jone{ [jumperguy setImage:[UIImage imageNamed:@"jumperguy_a_a3.png"]]; movement4 = [NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(jtwo) userInfo:nil repeats:NO]; } – Tyler Schoenau Jan 26 '15 at 01:59
  • Can you edit your question and paste everything there? Maybe some screenshots of the UI would help. Thanks. – Armin Jan 26 '15 at 01:59