I'm making a StopWatch, and I'm just a beginner, so please be patient with me.

I have two tabs. The first tab is a timer, while the second tab is a clock in string format. I have a few problems with both of them.

The problem with the timer is that it starts from January 1st, 2001. How can I modify my code so that it'll start from 0, and then go upwards (1, 2, 3, 4, 5, 6, 7, etc...)?

I'll post my code below.

The problem with the clock is that it can post the time in string format, but it won't update every minute after that. I also use awakeFromNib to post it, because, like i said, I'm just a beginner (first programming language also).

Here's the code for the timer:

- (IBAction)startWatch:(id)sender

{
        NSDate *currentDate = [NSDate date];

timer = [NSTimer timerWithTimeInterval:0 target:self selector:@selector(updateTextfield:) userInfo:nil repeats: YES]; [[NSRunLoop currentRunLoop] addTimer:timer forMode: NSDefaultRunLoopMode];
        [timer setFireDate:currentDate];
        [timer retain];
}


- (void)updateTextfield:(NSTimer *)timer

{
        
        NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
        
        NSTimeInterval startTime;
        
        NSTimeInterval difference = now - startTime;

        NSString *timeString = [NSString stringWithFormat:@"%f", difference];
        
        [textField setStringValue:timeString];
}


Here's the code for the clock:

- (void)awakeFromNib
{
        NSDate *someDate = [NSDate date];
        NSTimer *anotherTimer = [NSDate date];
        
        [clock setStringValue:anotherTimer];
}


Thanks to everyone!
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to