Re: Loop through NSTableView to set NSCell state
Re: Loop through NSTableView to set NSCell state
- Subject: Re: Loop through NSTableView to set NSCell state
- From: Bill Cheeseman <email@hidden>
- Date: Sun, 14 Apr 2002 16:08:22 -0400
on 02-04-14 10:44 AM, j o a r at email@hidden wrote:
>
Complying with the MVC pattern you should never need to enumerate over
>
the cells in the table view - the view is just there do display values,
>
not provide them. You have "the true" values in your model object.
A quibble:
I think of a table's datasource as part of the table's controller, bridging
the model and the view. That is, the contents of the datasource need not be
coextensive with the contents of the model. You might want to display
various subsets of the model in the table at different times. For example,
to filter the table according to one of multiple possible values in a column
(every record whose last name is "Smith," and so on). This is a very common
scenario. Both the model and the datasource are just arrays of pointers to
the actual records, so there normally isn't much of a memory penalty from
keeping them separate.
In such a case, it is important to know whether the questioner wants to
iterate over all the records currently displayed in the table (in which case
he should iterate over all the records in the possibly filtered datasource),
or instead over all the records in the model (in which case he should
iterate over all the records in the model).
You pointed out that he can use the model as the datasource and perform his
enumeration check when the table is reloaded using the table's delegate
methods. In such a case, the only way to enumerate over what is currently
displayed is to run the reload operation a second time. So there is nothing
gained by avoiding separation of the model and the datasource, because the
enumeration has to be performed twice in either case (once to display it,
and once to perform the testing operation the questioner asked about, which
sounded like it was to be done some time after the table was first
displayed). Having a datasource separate from the model is useful when you
want to perform many operations on a filtered subset, because then you don't
have to keep reloading the table -- which I assume takes time to update the
screen, and people have suggested that reloadData performs other operations
as well (although I have no idea what they might be).
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.