Re: NSDoc and Memory
Re: NSDoc and Memory
- Subject: Re: NSDoc and Memory
- From: Bill Cheeseman <email@hidden>
- Date: Tue, 03 Sep 2002 06:46:06 -0400
on 02-09-02 10:33 PM, Ricky Heywood at email@hidden wrote:
>
How can a NSDocument get its corresponding window at run time? There is an
>
IBOutlet called window but you do you get to it since it isn't explicitly
>
entered into my subclass of NSDocument (CheckRegController.h/m)
NSDocument does NOT have an IBOutlet named "window." What you're probably
seeing in IB is NSWindowController's IBOutlet named "window" -- assuming
your nib's File's Owner is a subclass of NSWindowController.
Basically, it goes like this, in a document-based application.
A document can have multiple windows. Therefore, every NSDocument subclass
inherits from NSDocument an instance variable named "windowControllers."
This is an array containing a reference to every window controller
associated with the document.
A window controller normally has one associated window. Therefore, every
NSWindowController subclass inherits from NSWindowController an instance
variable/IBOutlet named "window."
So, if you want your document to get a reference to one of its windows, keep
a reference to its window controller when you open it. Then you can use a
message something like this: [[self myMainWindowController] window]. If your
document has only one window, you don't have to track its window controller
but can instead just refer to the first (and only) window controller in the
array: [[[self windowControllers] objectAtIndex:0] window].
Usually, if the File's Owner is a subclass of NSWindowController, it's
easiest to think of the window controller as your main control point for a
window. A complex document-based application usually does it this way. Then
the window controller can get a reference to its window with [self window].
If you want to go in the opposite direction, every window inherits an
instance variable named "windowController" and every window controller
inherits an instance variable named "document."
All this is covered in Recipe 1 of my Vermont Recipes tutorial
<
http://www.stepwise.com/Articles/VermontRecipes>, and in many other books
and tutorials.
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
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.