Re: Rescheduling an NSTimer from a completion method
Re: Rescheduling an NSTimer from a completion method
- Subject: Re: Rescheduling an NSTimer from a completion method
- From: Fritz Anderson <email@hidden>
- Date: Wed, 12 Aug 2009 11:17:04 -0500
On 12 Aug 2009, at 10:55 AM, Christopher Kane wrote:
On Aug 11, 2009, at 10:28 AM, Fritz Anderson wrote:
iPhone OS 3.0
Can an NSTimer be rescheduled after firing, and after another trip
through the run loop?
I'd like to "reschedule" a NON-repeating timer in my own code. I
assume that in the simple case it would be something like:
- (void) handleTimer: (NSTimer *) aTimer
{
// ... do things ...
[aTimer setFireDate: someTimeInTheFuture];
[[NSRunLoop currentRunLoop] addTimer: aTimer forMode:
NSDefaultRunLoopMode];
}
I'm pretty sure that this is legal — am I right?
No, as you suspected farther down in your message. NSTimers which
are not repeating are one-shot -- they cannot be rescheduled.
Create a new NSTimer, when you next need it, and add it to the run
loop. [And also self.myTimerIvar = nil; in your timer handler as
you thought.]
Thank you very much indeed.
I think I'll file a radar on the documentation. My reading of the
class overview suggested to me that if the run loop could reschedule
repeating timers, I could reschedule a non-repeating one.
It does say, "If you specify that the timer should not repeat, it is
automatically invalidated after it fires," but elsewhere "invalidate"
is said to mean that it's removed from the run loop's queue -- which
suggested to me that it could be revalidated by putting it back.
But now I understand, and I thank you kindly for your help.
— F
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden