• 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: Stopwatch
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stopwatch


  • Subject: Re: Stopwatch
  • From: Clark Cox <email@hidden>
  • Date: Mon, 13 Jun 2005 08:44:37 -0400

On 6/13/05, Sanri Parov <email@hidden> wrote:
> On Sun, 12 Jun 2005 12:30:30 -0700, Shawn Erickson wrote:
>
> > Can you better explain the problem you are having? What are you doing
> > in that timer?
> >
> > Best to say what you end goal is in more detail not just how you are
> > currently going about it.
> >
>
> The goal is just to create a stopwatch for a more complex application;
> that's the thread subject.
> Just think about the one (probably) is on your wrist :-))
> I just want a textfield updated with hours, mins, seconds every second
> , no more.
> The main problem is that I'm not so excited using NSTimer, as far as
> I've never used it.
> Is this helpful?


Try something like (composed in mail, but should give you a general idea):

@interface StopwatchController : NSObject
{
  IBOutlet NSTextField *textField;
  NSTimer *timer;
  NSDate  *startTime;
}

-(IBAction)startOrStopTimer:(id)sender;
-(IBAction)timerFired:(id)sender;

@end

@implementation StopwatchController

-(void)startOrStopTimer:(id)sender
{
  if(timer)
  {
    [timer invalidate];
    [timer release];
    timer = nil;

    [startTime release];
    startTime = nil;
  }
  else
  {
    startTime = [[NSDate alloc] init];
    timer = [[NSTimer scheduledTimerWithTimeInterval: 1.0 target: self
selector: @selector(timerFired:) userInfo: nil repeats: YES] retain];
  }
}

-(void)timerFired:(id)sender
{
  NSDate *currentDate = [NSDate date];
  NSTimeInterval elapsedTime = [currentDate timeIntervalSinceDate: startTime];

  /*Update the field here, based on elapsedTime*/
}

@end


--
Clark S. Cox III
email@hidden
http://www.livejournal.com/users/clarkcox3/
http://homepage.mac.com/clarkcox3/
 _______________________________________________
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: 
 >Stopwatch (From: Sanri Parov <email@hidden>)
 >Re: Stopwatch (From: mmalcolm crawford <email@hidden>)
 >Re: Stopwatch (From: Sanri Parov <email@hidden>)
 >Re: Stopwatch (From: Shawn Erickson <email@hidden>)
 >Re: Stopwatch (From: Sanri Parov <email@hidden>)

  • Prev by Date: Re: UK Cocoa jobs?
  • Next by Date: observeValueForKeyPath:ofObject:change:context: called twice
  • Previous by thread: Re: Stopwatch
  • Next by thread: Re: Stopwatch
  • Index(es):
    • Date
    • Thread