Re: Creating a clock and updating a textfield
Re: Creating a clock and updating a textfield
- Subject: Re: Creating a clock and updating a textfield
- From: Tom Harrington <email@hidden>
- Date: Sun, 30 Oct 2005 18:28:54 -0600
On 10/29/05, Nima <email@hidden> wrote:
> Hi
> I'm trying to make a simple clock which is generated in a text field by
> clicking a button.
> //This code is supposed to trigger the clock
> NSDate *today = [NSDate date];
> [showTime setStringValue:today];
> While it does generate the current date and time, it fails to update it -
> and here's where my Obj-C experience fails me.
All you did there was pass a static string, so unless there's more you
didn't mention, there's no reason it would update.
> How do I go about to update the textfield?
> I did some research and found out that one way to do it is by implementing
> this code:
> //from http://www.cocoabuilder.com/archive/message/cocoa/2003/7/7/3275
> NSTimer *timer = [[NSTimer alloc] initWithFireDate:startTime
> interval:1.0 target:self selector:@selector(update:) userInfo:nil
> repeats:YES];
> But since I'm a Obj-C beginner I'm having a hard time using it in my own
> little application.
> Can someone give me a couple of pointers on how this specific task is to be
> dealt with?
Have you tried the documentation for NSTimer? You need to create a
method to match the selector argument, that exists on the target
argument. The start time is up to you, or you could use one of
NSTimer's other constructors that don't have that argument.
--
Tom Harrington
email@hidden
AIM: atomicbird1
_______________________________________________
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