Stop the NSTimer

Discussion in 'iOS Programming' started by jjgraz, Sep 29, 2009.

  1. jjgraz macrumors regular


    Feb 13, 2009

    I have a NSTimer which is fired on a button click, such as:

    [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(start) userInfo:nil repeats:NO];
    now i want to stop the timer before the actual method is called when a different button is clicked....Meaning, the first button has been pushed and the timer has been fired (5 second delay), but the other button has been pushed and stops the timer in it's track before executing the method.

    Is this possible?
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    It is. Just realize that scheduledTimerWithTimeInterval:target:selector:userInfo:repeats: returns a new NSTimer object. Store that and then take a peak at NSTimer's Class Reference to see if there's an instance method that can help you with the stopping part.

Share This Page