Re: Experimenting with Timers
Re: Experimenting with Timers
- Subject: Re: Experimenting with Timers
- From: Brian Webster <email@hidden>
- Date: Sun, 21 Oct 2001 14:27:30 -0500
Your target argument should be self, not nil. Also, the
UpdateCurrentTime: method should take an NSTimer* argument, not
just NSTimer, and it should return void instead of id.
A couple of Objective-C related observations:
1. You don't need to put the (NSTimeInterval), (SEL), (id), etc.
next to the arguments when you call the method.
2. In Objective-C, the convention is to have variable and method
names start with a lower case letter (e.g. updateCurrentTime
instead of UpdateCurrentTime). Words starting with capital
letters are usually class or type names, so your code below
looks kind of strange because it looks like you're calling a
whole bunch of class methods instead of methods on your instance
variables.
On Sunday, October 21, 2001, at 12:13 AM, cocoa-dev-
email@hidden wrote:
First off, I'd like to say thank you to everyone who has helped
me out in
the past. Everything there is working fine. I have yet more
questions, and
I'm sure this one won't be the last.
I'm working on setting up a timer, to update a text field every
second with
the current date. That's pretty generic, so here is the specific code:
-(id) UpdateCurrentTime: (NSTimer) Timer
{
[CurrentTime setObjectValue: [NSCalendarDate date]];
return self;
}
- (IBAction)ASet:(id)sender
{
SEL UCT = @selector(UpdateCurrentTime:);
[NSTimer scheduledTimerWithTimeInterval:(NSTimeInterval)1
target:(id)nil
selector:(SEL)UCT userInfo:(id)nil repeats:(BOOL)YES];
[SetWindow showWindow:self];
[CurrentDate setObjectValue: [NSCalendarDate date]];
[CurrentTime setObjectValue: [NSCalendarDate date]];
}
The most annoying part is, I know I'm missing something
obvious. I just
can't seem to put my finger on it, though. What I've tried to
do is make a
method to update the text field, which would be called by the
Timer every
second. I'm sure that my problem lays in the target and
userInfo arguments,
or in a line I'm omitting somewhere.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster