• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTimer fires after invalidated - why?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTimer fires after invalidated - why?


  • Subject: NSTimer fires after invalidated - why?
  • From: Walt Horat <email@hidden>
  • Date: Wed, 22 Mar 2006 20:19:58 -0800
  • Thread-topic: NSTimer fires after invalidated - why?

If a particular drawer is concealed when the user types, we want to open the
drawer and have it close after a period of time; each keystroke shall reset
the timer.

The following code does not work, while to my understanding it should. What
is wrong with my understanding?

-(void) keyDown: (NSEvent*) theEvent
{
    ...
    ...

    if ([m_drawer state] != NSDrawerOpenState)
    {
        [ m_drawer open];               // open, if not already

        [m_drawerCloseTimer invalidate];    // " Stops the receiver from
                                            // ever firing again and
                                            // requests its removal from its
                                            // NSRunLoop"
        [m_drawerCloseTimer release];

        m_drawerCloseTimer = [[NSTimer scheduledTimerWithTimeInterval: 5.0
                                       target: m_drawer
                                     selector: @selector(close:)
                                     userInfo: nil
                                      repeats: NO] retain];
    }
}

We start with a nil timer, so the first time through the invalidate and
release are no-ops.

We allocate a timer to fire 5 seconds in the future; the timer is wired
directly to the drawer close.

The actual behavior is that the drawer closes 5 seconds after the first
keypress, regardless of any keystrokes that occur in the interim.



Walt
Cisco Systems

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSTimer fires after invalidated - why?
      • From: Shaun Wexler <email@hidden>
    • Re: NSTimer fires after invalidated - why?
      • From: Walt Horat <email@hidden>
    • Re: NSTimer fires after invalidated - why?
      • From: Henry McGilton <email@hidden>
  • Prev by Date: Re: awakeFromNib vs appdidfinishlaunching
  • Next by Date: Source files - subclassing a nstableview
  • Previous by thread: Confused on releasing bindings in doc-based apps
  • Next by thread: Re: NSTimer fires after invalidated - why?
  • Index(es):
    • Date
    • Thread