• 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: problems resetting timer interval.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problems resetting timer interval.


  • Subject: Re: problems resetting timer interval.
  • From: Ron Fleckner <email@hidden>
  • Date: Fri, 30 Jan 2009 11:00:50 +1100


On 30/01/2009, at 9:07 AM, Memo Akten wrote:

Hi All, I'd like a function that sets up a timer, and can also change the frequency, but I just can't get it to work. If I call it more than once it just stops calling the timerLoop function altogether. I've tried so many things including not actually scheduling the timer in the setFrameRate function, but just saving the desired frameRate and setting a flag to notify that its changed, and in the next frame changing the time. I"ve tried not using the conveniance method but manually allocing the timer and adding to the current runloop, and releasing the old one before allocing the new one. But always same problem. First call to the function works, second and more calls don't. What am I doing wrong?

The function in its simplest form is below. How can I achieve what I want?

-(void) setFrameRate:(float)frameRate {
[timer invalidate];
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0f / frameRate) target:self selector:@selector(timerLoop) userInfo:nil repeats:YES];
}



Cheers,



Memo (Mehmet S. Akten)
	www.memo.tv
www.twitter.com/memotv
www.vimeo.com/memotv


I basically do the same and it works for me, but there are some slight differences.


Translating my setup into your terminology, I have an ivar float frameRate; It has accessors - (float)frameRate and - (void)setFrameRate:(float)newRate;

Then in my IBAction method which the user calls via the GUI, I set the new frameRate and call a -stopTimer method which invalidates the timer, then still in the IBAction method call a startTimer method which simply does what your "timer = [NSTimer scheduledTimer... ] method does.

Perhaps breaking out the parts like that helps?  I don't know.

HTH,

Ron


_______________________________________________

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


References: 
 >problems resetting timer interval. (From: Memo Akten <email@hidden>)

  • Prev by Date: Re: Interface Builder Plugin Dependency
  • Next by Date: Re: Interface Builder Plugin Dependency
  • Previous by thread: problems resetting timer interval.
  • Next by thread: viewDidLoad called after viewWillAppear:
  • Index(es):
    • Date
    • Thread