On Thu, Jul 17, 2008 at 5:35 PM, j o a r <[EMAIL PROTECTED]> wrote:
>
> On Jul 17, 2008, at 2:24 PM, Nick Zitzmann wrote:
>
>>> How on earth to I communicate with an object that has been instantiated
>>> by Interface Builder???
>>
>> Declare an IBOutlet pointer connecting an instantiated class to the
>> instantiated object. Then read the instantiated class's header file into IB,
>> which is normally done automatically, but you may have to do it manually if
>> you're working on a framework.
>
>
> ...but note that this is not how James would solve the concrete problem
> mentioned in the original message.
>
> In a document based application you don't have "the document", you have any
> number of documents. The AppDelegate doesn't just want a reference to any
> document, it's looking for some specific document. Typically that would be
> the document associated with the "main window" (check the documentation for
> more on what "main" and "key" window is in Cocoa). You could find that
> document like this:
>
>        NSApp > Main Window > Window Controller > Document

And furthermore, manipulating the active document from your NSApp
delegate is often not what you want. For things like menu items that
should apply to the active document, you'll want to connect to the
First Responder instead.

As an aside, if you do check the main window or ask
NSDocumentController for the current document, be aware that neither
one will work if your application is not frontmost at the time that
the code runs. For reasons I don't fully understand, -mainWindow
returns nil when the application is in the background, which shoots
this down. Obviously not a problem if you're responding to a GUI
event, but something to be aware of.

Mike
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to