NSTimer fires after invalidated - why?
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