Multiple NSWindowcontroller for the same NSDocument
Multiple NSWindowcontroller for the same NSDocument
- Subject: Multiple NSWindowcontroller for the same NSDocument
- From: Andrea Perego <email@hidden>
- Date: Tue, 18 Dec 2001 19:35:39 +0100
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.