Re: Controller knowing about an event
Re: Controller knowing about an event
- Subject: Re: Controller knowing about an event
- From: Mario Diana <email@hidden>
- Date: Mon, 26 Nov 2001 09:26:01 -0500
Maybe a fellow newbie ought to help ;-)
If you have two text fields and you want the contents coordinated, make
an outlet from the Controller for each of the fields (a separate one for
each). This enables the Controller to get a handle on the fields. Then,
make one action, something like sendContents(), and connect that action
twice: from each text field to the Controller.
What you have, now, is each text field being able to send a message to
the Controller, via the action, and the Controller being able to get and
set the contents of each text field, via the outlet.
(I have each field set up in IB to "send action only on enter," but I
don't think this is important.)
Here's the code in Java (if you don't read Java, what follows below is
simple, so don't worry.)
public class MyObject {
NSTextField textField1; // First text field
NSTextField textField2; // Second text field
// What you need to test for is object identity: are 'sender'
// and 'textField1' the same object, for example.
public void sendContents(NSTextField sender) {
if(sender == textField1) {
textField2.setStringValue(textField1.stringValue());
} else {
if(sender == textField2) {
textField1.setStringValue(textField2.stringValue());
}
}
}
}
Good luck!
I tried to make a window with 2 text fields, when one is updated the
other is updated with the same text.
how do I let the controller know about what is going on?