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: Christopher Kane <email@hidden>
- Date: Wed, 12 Aug 2009 08:55:13 -0700
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.]
Chris Kane
Cocoa Frameworks, Apple
_______________________________________________
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