On 5 Jun 2008, at 14:46, Johnny Andersson wrote:
To understand what I have problems with, let's suppose that I want to put a "module" consisting of an NSViewController, controlling the view with two buttons, which in turn contains a DrawView, on my main window. Do I put my DrawViewController in the root of the MainWindow NIB, and if so, how do I specify where the view will end up? Or, do I instantiate a a DrawViewController in my DrawView NIB, and put a DrawView directly into the main window?I know I'm not explaining this very well; I don't understand the concepts well enough to do that yet. If it helps, here's what I would have done if I was using Qt:1) Create DrawWidget2) Create FancyDrawWidget (containing the buttons, a DrawWidget and connections) 3) Create HandwritingWidget, which contains all the logic + a FancyDrawWidget.4) Plop a HandwritingWidget somewhere on my main window.I'd be grateful for any help - including help on "how to ask the right question".Kind regards, Johnny
It really depends on the larger architecture of your app on how you want to do this. The reason NSViewController exists is to offload view-specific code into a controller for that view (or view hierarchy) so that the code does not all go in your app controller or a window controller.
With something that was a simple 1 window app with a draw view as a subview of the window's content view and the buttons you describe also as subviews of the content view then a window controller may do. As you say though if you can encapsulate this better you can ease reusing this code.
I've written a sample app and post together with Cathy Shive on (what we think) is a good and general way of using NSViewController and the extras we've added to make it fit into the MVC paradigm properly, you can find it on her blog http://katidev.com The main way I would set this up is to create a view nib with your draw view (or your draw view as a subview of some other view) in it an little else (a contextual menu too perhaps) and set the file's owner of this draw view nib to an instance of NSViewController or a subclass thereof. All your code to control the view is then in the view controller and you have self- contained unit.
From here you can instantiate your view controller in your window controller and then set the view's position in -awakeFromNib of either the view or window controller. You could also, if you redesign later, instantiate your draw view controller during the setup of another view controller (or indeed some later time in the application's life) and set the draw view as a subview of whatever view this other view controller controls! This way you can set up as complex a controller hierarchy as you desire, and changing where the draw view is presented in your app boils down to moving the line in which you create your draw view controller and moving the view positioning code to somewhere else.
This setup is shown in the example code in the second article on Cathy's site. If you have any questions then don't hesitate to ask. You can also look at the thread that made us write about all this here
http://www.cocoabuilder.com/archive/message/cocoa/2008/3/19/201743 Hope this helps, Jon -- Espresso Served Here -- http://jonathandann.wordpress.com --
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list ([email protected]) 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]
