Re: Okay I have those pieces… now where's the glue?
Re: Okay I have those pieces… now where's the glue?
- Subject: Re: Okay I have those pieces… now where's the glue?
- From: Jens Alfke <email@hidden>
- Date: Tue, 27 May 2008 13:21:11 -0700
On 27 May '08, at 1:04 PM, Satsumac wrote:
How do I allow controller A to send commands to controller B and
vice versa?
If controller A initialized controller B, then A knew about B, but
what about the other way round?
I seem to remember this exact question coming up a few days ago...
If both are in the nib, add outlets to wire them to each other.
If A initializes B, then have A pass itself as a parameter to the
initializer, or set itself as a property on B (like a delegate), or
have A listen for notifications posted by B, or observe property
changes.
Controller A is my AppController and does all the general GUI stuff
like opening windows, swapping subviews, etc.
Controller B is the class that performs the actual task. Controller
B shall not have an instance in the nib. It gets its outlets by
being passes to the nib as File's Owner via "setDelegate".
It sounds like you have a multiple-nib application, where controller B
runs a window, and multiple instances can be opened.
In that case, the app controller A shouldn't be involved in the
details of the windows maintained by B. It should instantiate B when
told to open a new window, and then leave B to manage the window.
I then have a Button for invoking an action. NSButton sends an
action to Controller A which then does some GUI stuff and then tells
Controller B to perform its task.
Where is the button? If it's in the window managed by controller B,
then it should be connected to controller B instead.
During the execution of this task Controller B might notice that
something went horribly wrong and Controller A is highly needed to
update the GUI.
Again, A probably shouldn't be involved in B's GUI. You can use the -
presentError: method to send the error up the responder chain, and
have the application handle it.
You might want to look through some of the sample apps that use
documents and/or multiple windows, to see how they factor their code.
—Jens
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden