• 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
StopWatch Application Help
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

StopWatch Application Help


  • Subject: StopWatch Application Help
  • From: Eric Lee <email@hidden>
  • Date: Sun, 20 Jul 2008 13:53:14 -0500

I'm trying to make a stopwatch application, and I'm having trouble getting the Timer to fire, and then having the Text field being updated.

Here's the code:

AppController.h
----------------------------

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

- (IBAction)startWatch:(id)sender;
- (IBAction)stopWatch:(id)sender;

---------------------------

AppController.m

---------------------------

#import "AppController.h"


@implementation AppController

- (IBAction)startWatch:(id)sender
{
NSDate *currentDate = [NSDate date];
NSString *string = [timer value];
timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(startWatch:) userInfo:nil repeats: YES];
[timer isValid];
[textField setValue:string];
[[NSRunLoop currentRunLoop] addTimer:timer forMode: NSDefaultRunLoopMode];
[timer setFireDate:currentDate];
}
- (IBAction)stopWatch:(id)sender
{
[timer invalidate];
[timer release];
}


@end

-----------------------------------

I know that there is definitely some mistakes, as this is my first time using NSTimer, and NSTimeInterval (i'm trying to learn this class for another application).

Thanks!
_______________________________________________

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


  • Follow-Ups:
    • Re: StopWatch Application Help
      • From: Marco Masser <email@hidden>
  • Prev by Date: Re: drawRect infinite loop -- argh!
  • Next by Date: Re: looking for help with http post example
  • Previous by thread: Re: looking for help with http post example
  • Next by thread: Re: StopWatch Application Help
  • Index(es):
    • Date
    • Thread