Hi Eric,

The best thing to tell you to do, I think, is to read, or re-read, the documentation for NSTimer. A timer (ie, an NSTimer instance) will fire when you tell it to. In your startWatch: method, you've told it to fire every 0 (zero) seconds. I don't think that's what you want.

In your -awakeFromNib, you're declaring a pointer to an NSTimer, but assigning a date to it. I don't think that's what the timer wants.

HTH,

Ron


On 02/08/2008, at 3:31 PM, Eric Lee wrote:

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/ronfleckner% 40ozemail.com.au

This email sent to [EMAIL PROTECTED]
_______________________________________________

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