Re: Best data source for table view in document window
Re: Best data source for table view in document window
- Subject: Re: Best data source for table view in document window
- From: Andy Lee <email@hidden>
- Date: Wed, 05 Sep 2012 16:46:47 -0400
On Sep 5, 2012, at 11:24 AM, Kyle Sluder <email@hidden> wrote:
> On Sep 5, 2012, at 5:39 AM, Jerry Krinock <email@hidden> wrote:
>
>> What is the best the data source for a table view in a document window? The candidates areā¦
>>
>> (1) Category of the document. This is the way it is done in the WithoutBindings ("With and Without Bindings") Apple sample code. But it seems like too much "view-ish" code in the data model, particularly when my document class is also used in a GUI-less command-line tool, which has no need for this code.
>
> NSDocument is really a controller.
Yup, and a data source is by nature a controller object: it mediates between a view (see the first argument to each data source method) and a model. Your document, your window controller, or a view controller would all be good candidates to be data sources.
>> (4) Category of the table view itself, assuming that it is subclassed. Seems like a logical division. No worrying about whether table view or its data source gets deallocced first. Access the document via [[[self window] windowController] document].
>
> Absolutely, completely, 100% not. Never ever do this. If NSTableView privately implements any methods that it also expects the data source to implement, you will get bad behavior.
Not only that, you'd be putting controller-ish stuff (and, by necessity, model-ish stuff) into the view. The point of a data source is like the point of a delegate: so you can customize an object's behavior without having to subclass and without violating MVC.
--Andy
_______________________________________________
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