Re: Advise on referencing NSDocument from custom view
Re: Advise on referencing NSDocument from custom view
- Subject: Re: Advise on referencing NSDocument from custom view
- From: Quincey Morris <email@hidden>
- Date: Sun, 10 Aug 2014 14:05:45 -0700
On Aug 10, 2014, at 13:16 , Luc Van Bogaert <email@hidden> wrote:
> Let's see if I understand this correctly: do you mean I could create a separate model class, eg. "Drawing" with all of it's properties and reference this in my document class as an instance variable or even as a property.
> Then, from my custom view, instead of using [[self.window.windowController document] someProperty]', I could use '[self.window.windowController someProperty]', which in turn would message my model object to return the value of 'someProperty' using 'return [self.document someProperty]' ?
To be specific:
In a document-based app, I will generally have MyDocument, MyWinController and MyModel.
MyDocument has a MyModel property, referencing the model that it loaded from the document file (or whatever).
MyWinController has a MyModel property, referencing the same model as the document.
A custom MyView would also have a MyModel property referencing the same model, initialized in any of various ways depending on how the view was created. The view would then use myModel.someProperty whenever it needed it, perhaps even binding to it.
Putting a derived “someProperty” directly on the window controller, or even on a view controller, *is* feasible too. Often, I find, I use this approach when the view presents a somewhat transformed picture of the data model. Databasey kinds of apps (such as master/detail) often seem to want to use the real data model directly. UIey kinds of apps often seem to want to use a transformed model.
_______________________________________________
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