Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimer



I think you need to add something like

       [[NSRunLoop currentRunLoop] addTimer: timer forMode: NSDefaultRunLoopMode];

for your timers in order to have the run loop run them; otherwise, I think you've created objects that actually aren't going to do anything but sit there.

On Wednesday, August 31, 2005 Christopher Hickman <email@hidden> wrote:

>Message: 2
>Date: Wed, 31 Aug 2005 14:38:58 -0400
>From: Christopher Hickman <email@hidden>
>Subject: NSTimer
>
>Hi folks,
>
>I have an NSTimer that I'm trying to use to periodicly call a method.   
>The timer gets created, but it doesn't call my method when it fires.  Here's my code, do you see anything wrong?
>
>-(void)incrementProgressIndicator;
>{
>	NSLog(@"incrementProgressIndicator"); //Never logs
>	//progressIndicator is an NSProgressIndicator IBOutlet of this object
>	//incrementAmount is a double ivar with a written accessor
>	if (progressIndicator != nil) {[progressIndicator incrementBy:[self incrementAmount]];}
>}
>
>-(void)incrementProgressIndicatorEveryTimeInterval: 
>(NSTimeInterval)seconds iterations:(int)iterations;
>{
>	NSLog(@"incrementProgressIndicatorEveryTimeInterval: %f iterations: %i", seconds, iterations);
>	NSTimer *incrementerTimer;
>	NSInvocation *incrementerInvocation;
>
>	incrementerInvocation = [NSInvocation invocationWithMethodSignature: [self  methodSignatureForSelector:  @selector(incrementProgressIndicator)]];
>
>	incrementerTimer = [NSTimer scheduledTimerWithTimeInterval:seconds invocation:incrementerInvocation repeats:YES];
>
>	//incrementerTimer needs to be invalidated after it fires (iterations) times, so we set up a
>	//second timer to wait (seconds * iterations) seconds and invalidate the original timer
>	[NSTimer scheduledTimerWithTimeInterval:(seconds*iterations) invocation:[NSInvocation invocationWithMethodSignature: [incrementerTimer methodSignatureForSelector:@selector(invalidate)]] repeats:NO];
>
>}

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.