Skip navigation.
 
mlRe: Correct use of NSViewController
FROM : Cathy Shive
DATE : Thu Mar 20 08:40:00 2008

I would do it exactly like you described.  Seems to me that your 
instincts are pretty much on the mark.  In your case, the window 
controller could take care of creating that first main split view, 
but I would do it in the first level of the view controller 
controller tree for logical consistency.  So in a set up like mine 
and maybe yours, the window controller is only responsible for the 
window's content view.  It creates the first view controller, asks it 
for its view (the split view) and adds it as a subview to its own 
view (the window's content view).  And actually, when the window 
controller asks that first view controller for its view, if things 
are set up right in the controller tree, that view should contain the 
entire view hierarchy, which was built in nice little steps by each 
sub-controller in the tree.

I recently had to refactor my view controller set up because I 
started to notice similar bloat and spaghetti code creeping into the 
app.  I had all of the same questions you do about where things 
should happen.  :)  It was a bit tricky at first, but things fell 
into place and it feels very solid and clean to me now.  I also deal 
with a lot of dynamic adding/removing views.

Actually, I sent a bug report (Bug ID# 5794739)  to Apple last week 
because the documentation on "Document-Based Application Architecture"

http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/
Concepts/OverviewDocArchitecture.html#//apple_ref/doc/uid/20000023-
BAJBBBAH

hasn't been updated to explain the role of the new NSViewController 
class in this design.  Also, the issue you are dealing with now and 
that I dealt with a couple of weeks ago seems like it should already 
be dealt with in the design NSViewController.  As it is, it's very 
unclear what you're supposed to do with this class.

Anyway, best of luck, you seem to already know what you have to do :)

Cathy


On Mar 20, 2008, at 2:19 AM, Jonathan Dann wrote:

> Hi Cathy,
>
> Thanks for the comprehensive answer to my question, I wanted to 
> make sure that I wasn't committing heresy by going down the 'tree 
> of view controllers' road before jumping in and refactoring all my 
> code.  I was hoping to set it up so I could forget about most of 
> the memory management as I'm replacing views all over the place at 
> runtime.
>
> Out of interest, when I add my main split view, I then have to set 
> its size to fit my document window's content view.  As this task is 
> view-related it seems like it the split view's NSViewController 
> should handle the size calculation and placing of the view in the 
> correct place in the window.  I allocate and instantiate my view 
> controller in my NSWindowController subclass, then set the split 
> view as a subview of the content view and then  in the -
> awakeFromNib of the view controller I get the split view's 
> superview's (the content view's) frame, doing my resiing from there.
>
> Would you do the same, as this seems to encapsulate the logic 
> properly, or would you just set it all in the window controller?
>
> Thanks again, you've been really helpful.
>
> Jonathan

Related mailsAuthorDate
mlCorrect use of NSViewController Jonathan Dann Mar 19, 12:37
mlRe: Correct use of NSViewController Cathy Shive Mar 19, 13:19
mlRe: Correct use of NSViewController Jonathan Dann Mar 20, 02:19
mlRe: Correct use of NSViewController Cathy Shive Mar 20, 08:40
mlRe: Correct use of NSViewController Jonathan Dann Mar 20, 12:35
mlRe: Correct use of NSViewController Cathy Shive Mar 20, 13:29
mlRe: Correct use of NSViewController Paul Szego Mar 20, 23:27
mlRe: Correct use of NSViewController Jonathan Dann Mar 21, 21:49
mlRe: Correct use of NSViewController Cathy Shive Mar 21, 22:31
mlRe: Correct use of NSViewController Steve Weller Mar 22, 04:25
mlRe: Correct use of NSViewController Steve Weller Mar 22, 04:31
mlRe: Correct use of NSViewController Cathy Shive Mar 22, 05:18