RE: NSTimer
RE: NSTimer
- Subject: RE: NSTimer
- From: "Christopher Hickman" <email@hidden>
- Date: Wed, 31 Aug 2005 17:22:45 -0400
> -----Original Message-----
> From: Cameron Hayne [mailto:email@hidden]
>
> > -(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]];}
> > }
> >
>
> What is that semicolon doing after the "incrementProgressIndicator"
> in the first line?
It's optional. But, since you can do it, I do. That way the method
implementation first line exactly matches its declaration in the header. I
learned this only recently from Wil Shipley's Pimp My Code feature. :)
> > incrementerInvocation = [NSInvocation
> > invocationWithMethodSignature:
> > [self
> > methodSignatureForSelector:@selector(incrementProgressIndicator)]];
> >
>
> You don't seem to be setting the selector (or target) for that
> invocation. Read the docs on 'invocationWithMethodSignature'.
> But it would be far easier to just use the methods of NSTimer that
> take a selector instead of an invocation.
Right, I wasn't. Once I realized that and did, it worked. The NSTimer
factory method that takes a selector, +[NSTimer
scheduledTimerWithTimeInterval:target:selector:userInfo:repeats:], requires
a selector with a method signature that matches
-(void)myTimerFireMethod:(NSTimer*)theTimer, and since I want to be able to
use it both with the timer and without (mostly with call method from
AppleScript Studio), I didn't want to force an NSTimer argument. I suppose
I could just implement, say, a -incrementProgressIndicatorFromTimer: method
that just calls -incrementProgressIndicator. That's not a bad idea,
especially since I can use the userInfo parameter to set an "increment
until" parameter to invalidate it conditionally in the method, rather than
fire a second timer.
I think I'll do just that. Cool, thanks.
> > //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
> >
>
> You should just keep a counter and check it when your timer
> fires and
> invalidate the timer if the number of iterations has been reached.
Oh, hey, this is pretty much what I just decided to do. Thanks.
Topher
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
References: | |
| >Re: NSTimer (From: Cameron Hayne <email@hidden>) |