Re: Apple MVC and Document Based application confusion.
Re: Apple MVC and Document Based application confusion.
- Subject: Re: Apple MVC and Document Based application confusion.
- From: Bill Garrison <email@hidden>
- Date: Sun, 29 Nov 2009 21:10:27 -0500
On Nov 29, 2009, at 6:58 PM, Sandro Noël wrote:
From what I read the MyDocument Class is supposed to be a model
controller, not the window controller.
The MyDocument Class is supposed to be able to host an array of
window controllers.
NSDocument has the capability to host an array of window controllers,
but you might not need that capability. NSDocument, out of the box,
will create its own internal window controller to manage the window
contained in the MyDocument xib. The whole document-based app
template is geared toward the simplest case, where there's one window
per document, loaded from a nib.
I see that makes sense if I have a main data view window and I would
want to associate an inspector
to that window and share the same data source with both windows. and
I like that idea.
Then you will want to look at bypassing the default behavior from
NSDocument.
You'll want your own window controller class to manage the main window
and another to manage the inspector. You'll want to override the -
makeWindowControllers method in your MyDocument class to manually
create the main window controller (and maybe the inspector controller
as well).
what i am unsure of is how to go about with interface builder, and
where should i associate the view with it's controller
inside the MyDocument Class? ( but i read that model should have no
knowledge of the view)
is it the same for the Model Controller?
What I would do is create a subclass of NSWindowController that will
be the main window manager; MainWindowController.h and
MainWindowController.m.
In IB, create a new window xib. The easiest thing is to name it
similarly to your window controller class: MainWindowController.xib.
In this window nib, change the File's Owner to be of class
MainWindowController. Also take care to hook up the window instance
in File's Owner to the window in your nib.
Taking this approach removes all the view-related stuff out of the
document, leaving it to just (mostly) concentrate on the model.
if it's not then MyDocument Class becomes more than a Model
Controller it is also a Window controller.
in witch case why bother creating separate View/Window controllers?
and why host an array of window controllers?
For the simple case of one window per document, there's no strict need
to create a separate window controller. You'd just throw everything
into the MyDocument class. It might be smelly, but it's fine for
really simple apps. Usually, though, it doesn't take long before the
app is complicated enough to warrant a separate NSDocument and
NSWindowController class(es).
Do i create the Window controllers in IB or do i do it in code, and
how would i go about doing that the right way?
I would create the window controllers in code. The main window
controller from within the MyDocument -makeWindowControllers method.
The inspector window controller you'd probably create some time later,
lazily, when the user first asks for the inspector.
Bill_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden