Re: NSTimer fires after invalidated - why?
Re: NSTimer fires after invalidated - why?
- Subject: Re: NSTimer fires after invalidated - why?
- From: Cameron Hayne <email@hidden>
- Date: Thu, 23 Mar 2006 12:04:34 -0500
On 23-Mar-06, at 2:22 AM, Andreas Mayer wrote:
Just for the record - there's a way to even avoid explicitly
allocating a timer:
[NSObject cancelPreviousPerformRequestsWithTarget:m_drawer
selector:@selector(close:) object:self];
[m_drawer performSelector:@selector(close:) withObject:self
afterDelay:5.0];
I have found this mechanism quite useful in past projects and have
packaged it into the following utility method:
// The following is a utility routine that is used for postponing a
selector
// until after some activity is finished.
// It is designed to be repeatedly called while the activity is ongoing
// and it will result in the selector being invoked exactly once
// after the activity has finished.
+ (void)performOnce:(SEL)aSelector
withTarget:(id)aTarget
withObject:(id)anArgument
afterDelay:(NSTimeInterval)delay
{
// cancel any pending requests of this type
[NSObject cancelPreviousPerformRequestsWithTarget: aTarget
selector: aSelector
object: anArgument];
// schedule the request
[aTarget performSelector: aSelector
withObject: anArgument
afterDelay: delay];
}
--
Cameron Hayne
email@hidden
_______________________________________________
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