StopWatch Application Help
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