Re: DocumentController & ApplicationController: messages between them?
Re: DocumentController & ApplicationController: messages between them?
- Subject: Re: DocumentController & ApplicationController: messages between them?
- From: Matt Neuburg <email@hidden>
- Date: Mon, 13 May 2002 11:11:39 -0700
On Sun, 12 May 2002 02:24:02 +0100, Diggory Laycock <email@hidden> said:
>
I have a Class called AppController that is a delegate of NSApplication
>
and does certain stuff throughout the life of the app.
>
>
I also have a class called MyDocument that controls documents
>
(obviously!)
>
>
I have a control (an NSPopUpButton) in the Document's nib that I would
>
like to populate from application-specific objects (not document
>
specifc).
>
>
So my question is: How do I send a message from my document to another
>
object that isn't in the same nib?
First, read:
Cocoa/TasksAndConcepts/ProgrammingTopics/LoadingResources/index.html
That gives the basic answer. In your document nib, some class is the File's
Owner. Now, either that class *is* your AppController class, in which case
you can just draw the connection, or that class was instantiated
programmatically, in which case whoever instantiated it will presumably be
someone who can see the AppController instance (in fact it will probably
*be* the AppController instance) and can hand it a reference to the
AppController instance so that its methods can access the AppController
instance.
There are a couple of other devices that can help you. Objective-C has
class methods. These are universally visible - you don't need a reference
to an instance in order to get at them. True, this won't give you direct
access to the ivars of a particular instance, obviously, but it can be
helpful, especially in singleton situations.
Also, Cocoa has notifications. This means that any instance can talk to any
other instance by prior arrangement (the prior arrangement is simply that
both instances must know the name of a notification they are going to use
to communicate). A notification can include a reference to an object,
typically the sender; so the recipient has a way to "reply".
m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes gar anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.