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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to