Re: Multiple NSWindowcontroller for the same NSDocument
Re: Multiple NSWindowcontroller for the same NSDocument
- Subject: Re: Multiple NSWindowcontroller for the same NSDocument
- From: Raphael Sebbe <email@hidden>
- Date: Tue, 18 Dec 2001 20:52:35 +0100
I have the same situation and here is my solution.
From a global object (that can be your application delegate, for
example), I implement this:
- (IBAction)newViewingWindow:(id)sender
{
NSWindowController *wc;
if([NSBundle loadNibNamed:@"ViewingWindow" owner:self])
{
wc = [[[NSWindowController alloc] initWithWindow:_tempWindow]
autorelease];
[[self currentDocument] addWindowController:wc];
}
}
As you notice, that object has a _tempWindow (temporary outlet)
connected from the just loaded NIB. It serves for creating the
NSWindowController that is next added to your document. Note that you
can get the current document through the NSDocumentController, I believe
(I just have a quick access through self here)
Also note that for me, those are secondary windows (different from my
'main' document window) and they are only created upon user request,
after the document has been created. In that sense, it may be slighty
different for you.
There should be other solutions (using NSWindowController to load the
NIB), but I retained this one for some reason I can't remember right now.
Hope this helps,
Raphael
On Tuesday, December 18, 2001, at 07:35 PM, Andrea Perego wrote:
Hi!
In my document-based project, a window displays a single part of a
document
(a spectrum, while the document consists of an array of spectra).
Therefore,
I'd like to allow the user to have more than a window open for the same
document, so that different spectra are displayed at the same time. To
achieve this goal, I've added a "New window" item to the "Windows"
menu, whose action message is received by the instance of my NSDocument
subclass (MySpectraDocument) that refers to the main window. A new
controller is created by means of
........
controller=
[[MySpectrumWController allocWithZone:[self zone]]
initWithNumber:aNumb];
[self addWindowController:controller];
........
exactly as it is done in "makeWindowControllers" for the first
controller instance. [mySpectrumWController initWithNumber:..] calls
in turn
self = [super initWithWindowNibName: @"MySpectraDocument"];
..............
to load its window etc.
Since each window plays exactly the same role, but for displaying a
different
spectrum from the collection, I guessed I might use the same nib file
for all of them.
In fact, while my application manages correctly a multi-window
environment where each window belongs to a different document, whenever
I try to create a further
controller/window for a document as outlined above, a new controller is
instantiated but neither "windowWillLoad" nor "windowDidLoad" is called
for it, and the corresponding window never appears.
As a check, I tried to create more than a controller directly in
[mySpectraDocument makeWindowControllers];
i.e. where normally the first controller/window is created: in this
case,
all the corresponding windows are loaded and displayed.
I fear I miss something in the complex relationship among Document <->
WindowController <-> nib file <-> window, but, up to now, re-reading
the docs
was of no use to me. If someone of you can see immediately the mistake
I'm doing, I'll be glad to stand corrected.
TIA
Andrea Perego
University of Florence - Phys. Dept.
_______________________________________________
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.