Re: windowcontroller neccessary?
Re: windowcontroller neccessary?
- Subject: Re: windowcontroller neccessary?
- From: James DiPalma <email@hidden>
- Date: Tue, 14 Jan 2003 00:08:35 -0800
From: Mike Ferris <email@hidden>
If you are using NSDocument then the document windows will always
have a windowController. For non-document windows, you can do what
you like, but NSWindowController is a really good class to start
with for your File's Owner.
I prefer allowing an NSDocument subclass to own a document's primary
nib file.
From: Mike Ferris <email@hidden>
Even if you use the simpler setup where the NSDocument is the nib file
owner (as in the doc-based app template project), NSDocument uses an
NSWindowController behind the scenes to handle the nib file.
Yes. Both of these designs use NSWindowControllers and both designs
could also use an NSWindowController subclass. I do not consider (i.e.
this is an opinion) either design simpler except that PB's document
template sets MyDocument as its document nib's file's owner. Both
designs work well for simple and for complex applications.
Also, note that if you will ever have any of the following situations,
you will ultimately want to do a separate NSWindowController subclass
(or several):
These points are also made in a FAQ within NSDocument's programming
topic:
- Your documents will support multiple views, for example if the
user wants to have one window zoomed in and another showing actual
size of the same document.
- Your document needs several different windows to represent it,
for example a CAD program that has windows for front, side, top, and
rendered views (this could probably be done without custom
NSWindowControllers, but it is easiest to have a window controller per
window, usually.)
A document with multiple windows requires that each NSWindowController
gets added to its document using -addWindowController. Documentation
(see "Creating a Subclass of NSDocument") recommends overriding
-makeWindowControllers.
If a document does not use NSWindowControllers to control its views,
then there is no requirement to subclass NSWindowController to allow a
document to have multiple windows.
- Your document is complex enough to justify factoring it into
model-handling and view-handling logic just for the organizational
advantages.
I think this point refers to using an NSDocument subclass as a
view-handling controller (an approach taken by many including a few
Cocoa books) and as a model-handling object (which it must play some
role in since open/save requests do pass through NSDocument). When a
document gets complex, an NSWindowController subclass can take over
view-controller responsibilities.
I never understood this point until a few moments ago; if I misspoke,
someone should correct my statements.
Views can also be controlled by NSObject subclasses that are
nib-instantiated along with their controlled views. I learned this
technique long before NSDocument and NSWindowController were written
and still use it today because I feel comfortable nib-instantiating
NSObject subclasses.
What I am describing is only one point of view which I am only
expressing to point out that there are options when it comes to
designing an application. I still recommend against using
NSWindowControllers as file's owners and against using them as view
controllers, but it is more important to feel comfortable with and
understand your application's design.
I hope that no-one reading this is now more confused.
-jim
_______________________________________________
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.