Re: Controller knowing about an event
Re: Controller knowing about an event
- Subject: Re: Controller knowing about an event
- From: Angela Brett <email@hidden>
- Date: Mon, 26 Nov 2001 22:17:18 +1300
Hi,
I'm trying to create extremely simple apps and getting confused...for
example I tried to make a window with 2 text fields, when one is update the
other is updated with the same text.
Well, this wouldn't teach you anything so it wouldn't be very good to
do it in this example, but in future you might find it useful to know
that you can do that just by connecting the text fields in Interface
Builder so that the action of one is to takeStringValueFrom: the
other. Whew, what a long sentence.
My 2 ideas:
* Subclass NSTextField and override the method that is called when the text
is changed and then have an outlet to the controller that let's it know
about the event so it can update the other text field?
You don't need to subclass it... just make your controller the
NSTextField's delegate, and implement textDidChange: (or one of
NSTextField's other delegate methods) in your controller.
* Or would it be better to setup the controller in the NSNotificationCenter
so that it receives news of the event that way?
I guess that would work too... I haven't used notifications yet as
I'm a newbie myself. If you're just making this project as a practice
exercise it would probably be a good idea to do it one way and then
do it the other way, so that you learn both ways. I think the idea is
to use the first way if you know which object is going to be
controlling the text fields, or use notifications if there are going
to be several different objects which want to know what's happening
to the NSTextField(s).
--
Angela Brett email@hidden
http://acronyms.co.nz/angela
A mathematician is a machine for turning coffee into theorems -- Paul Erdos