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

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to