• 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
NSTimer firing issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: NSTimer firing issue
      • From: Julian Pellico <email@hidden>
  • Prev by Date: openURL and Bookmarked location
  • Next by Date: Re: How to disable Apple's Bug Report Dialog when application crash?
  • Previous by thread: Re: openURL and Bookmarked location
  • Next by thread: Re: NSTimer firing issue
  • Index(es):
    • Date
    • Thread