Re: newbie interface problem
Re: newbie interface problem
- Subject: Re: newbie interface problem
- From: Chris Hanson <email@hidden>
- Date: Tue, 4 Oct 2005 17:38:03 -0700
On Oct 4, 2005, at 4:07 PM, Bob Sabiston wrote:
I am having some trouble with a bunch of interface controls. On
my window, I have about 10 different text fields and buttons that I
am trying to set from my code. Each field and button I have
connected to an outlet in my class. I use something like the
following to set them:
- (void)setDuration:(double)d {
[duration setDoubleValue: d];
NSLog(@"set Duration to %lf",d);
}
where 'duration' is the outlet name for a text field.
As others have mentioned, -setDuration: looks like a key-value coding
accessor method for the key "duration". I assume you probably also
have a -duration method that does a [duration doubleValue], correct?
If so, this is effectively using a control as storage for your data
model, which I normally would recommend against.
Instead, I'd have a durationField outlet (and other similarly-named
outlets to controls) that is manipulated in a couple of methods which
populate and take input from your controls. Either that, or I'd use
Cocoa bindings to directly wire your controls to their associated
model objects. Either of these will help keep the distinction
between manipulating your controls and manipulating your data model
clear.
The problem is that only two of the controls are working. Two of
the text fields show up properly. The other 8 text fields and all
of the switch buttons do not show anything. According to the NSLog
call, it is calling the functions with the proper values--I just
don't see anything. I've checked the IB connections and they all
look right. It is very weird since two of the text fields are
working. I can't find any difference between the two that are
working and those that aren't.
In what method are you actually invoking these methods? Are the
outlets to your other controls actually connected at the time you're
invoking these methods? I suspect they aren't, from which I deduce
you may be calling these in an -init method for a controller object
that you instantiate in a nib file. If this is what you're doing,
you'll want to populate control values using -awakeFromNib instead
since it's only invoked after the nib's entire object graph is
unarchived and connected.
-- Chris
_______________________________________________
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