• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Rescheduling an NSTimer from a completion method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Rescheduling an NSTimer from a completion method
      • From: Fritz Anderson <email@hidden>
    • Re: Rescheduling an NSTimer from a completion method
      • From: Jean-Daniel Dupas <email@hidden>
References: 
 >Rescheduling an NSTimer from a completion method (From: Fritz Anderson <email@hidden>)

  • Prev by Date: Re: NSDateFormatter formats from NSLocale
  • Next by Date: Re: Maintaining an ordered array of attributes in an NSTextStorage subclass
  • Previous by thread: Rescheduling an NSTimer from a completion method
  • Next by thread: Re: Rescheduling an NSTimer from a completion method
  • Index(es):
    • Date
    • Thread