On Sep 5, 2012, at 11:24 AM, Kyle Sluder <k...@ksluder.com> wrote: > On Sep 5, 2012, at 5:39 AM, Jerry Krinock <je...@ieee.org> 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 (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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com