Re: Sharing a model
Re: Sharing a model
- Subject: Re: Sharing a model
- From: Graham Cox <email@hidden>
- Date: Mon, 14 Feb 2011 16:27:35 +1100
On 13/02/2011, at 7:57 PM, Scott Steinman wrote:
> I'd like to split up the controller class into more manageable parts. I'm hoping to have one controller for the graphics NSView alone and another for everything else in the window. Both controllers would need access to the same model. What is the best way to accomplish this?
There's no "One True Way™", but there are several straightforward possibilities.
Just create outlets (IBOutlet) to each object and hook them together in IB. It probably makes most sense to use the document-based app structure and in your document subclass just have outlets for the model and each controller. Instantiate the model and controllers in IB.
> 1. Where should I instantiate and later dealloc the model object?
If you do this in IB, it will be taken care of.
> 2. How do I get both controllers to reference this single model without creating coupling between the controllers?
Give each controller a 'model' outlet that you connect to the model in IB. Each controller can get the model using [self model] (or whatever you name the property) without reference to anyone else. Similarly, each controller has outlets for the controls and views each one manages.
> 3. When should the reference to the model be set up in each controller?
It will be done for you when the document is created from the nib. All you need to do is populate the model from the file when the file is opened. NSDocument provides an override for that.
--Graham
_______________________________________________
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