NSTimer firing issue
NSTimer firing issue
- Subject: NSTimer firing issue
- From: Julian Pellico <email@hidden>
- Date: Thu, 22 Jul 2004 00:30:05 -0700
Hi group,
First I'd just like to say that this has been a great list for a
budding Cocoa developer. I've always found the answers to be right on
:-D
Now, I'm doing some animation in my app and I want it to be controlled
by playback buttons. I keep an NSTimer* in a custom view that
receives commands from my app controller. At a certain point in the
app, I want playback to start occurring automatically, so I invoke the
playForward method below from my app controller. However, the timer
does not successfully fire at that point. I have to press my play
backward button in my app, or pause and then forward again in order
for the timer to fire.
The following code is in a custom view. The mode is initially PlaybackPause.
- (void) pause
{
if (mode == PlaybackPause)
return;
mode = PlaybackPause;
// Invalidate the timer
[animationTimer invalidate];
[animationTimer release];
animationTimer = nil;
}
- (void) playBackward
{
if (mode == PlaybackReverse)
return;
mode = PlaybackReverse;
// invalidate the timer
[animationTimer invalidate];
// release the current timer
[animationTimer release];
// create a new timer
animationTimer = [NSTimer scheduledTimerWithTimeInterval: ANIMATION_INTERVAL
target: self
selector:
@selector(solverViewAdvanceFrame)
userInfo: nil
repeats: YES];
[animationTimer retain];
}
- (void) playForward
{
if (mode == PlaybackForward)
return;
mode = PlaybackForward;
// invalidate the timer
[animationTimer invalidate];
// release the current timer
[animationTimer release];
// create a new timer
animationTimer = [NSTimer scheduledTimerWithTimeInterval: ANIMATION_INTERVAL
target: self
selector:
@selector(solverViewAdvanceFrame)
userInfo: nil
repeats: YES];
[animationTimer retain];
}
// Frame advancement
- (void) solverViewAdvanceFrame
{
NSLog(@"ANIMATE");
}
///////// END CODE SNIPPET
The debugger shows that animationTimer is 0x0 on that first run
through playForward, as expected. However, solverViewAdvanceFrame
isn't getting called. I don't get why the timer isn't firing at all
initially.
Feel free to ask for more code if that would help, or more info.
Thanks,
Julian
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.