Re: Simple question. I guess...
Re: Simple question. I guess...
- Subject: Re: Simple question. I guess...
- From: Ondra Cada <email@hidden>
- Date: Tue, 31 Jul 2001 10:12:18 +0200
Mathieu,
>
>>>>> Mathieu Labrie (ML) wrote at Mon, 30 Jul 2001 21:52:03 -0400:
ML> Hi, I'm new to Cocoa / Obj-C programming and I just encounter a problem
ML> while programming a very small and easy application. I haven't bought
ML> the Learning Cocoa book and I don't have much documentation so I'm
The online docs are pretty good, incidentally.
ML> relying to you to help me finishing this little introduction application.
ML>
ML> The small application is supposed to let the user enter his name, let
ML> the user click the validation button and then print the user's name in a
ML> regular text field. I have my nameBox and my nameField.
If the nameField is an outlet bound in IB to a NSTextField, and the nameBox
is a string variable of yours, filled some way, and the button is bound to
the click: action, it should work well.
ML> The code for my controller is:
ML> - (IBAction)click:(id)sender
ML> {
ML> [nameField setStringValue:nameBox];
ML>
ML> }
If, though, the nameBox -- as its name implies -- is another NSTextField,
you should use
[nameField setStringValue:[nameBox stringValue]];
If it happens to be a NSTextView, then the proper way is
[nameField setStringValue:[nameBox string]];
(incidentally, I've always felt this inconsistency was a NeXT's bad design:
the classes IMHO should be polymorphic. For bigger projects I even add a
category "@implementation NSTextView (Consistency) -(NSString*)stringValue {
return [self string]; } @end" so as I can bind freely any view to any outlet
without need to change code)
ML> For an unknow reason, my namField didn't show the nameBox value when the
ML> validation button is pressed.
Looks like you haven't bound the button to the action in the IB? Or,
perhaps, some outlets?
Check whether the action gets called, and check whether the outlets are not nil.
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
private email@hidden
http://www.ocs.cz/oc