Re: Outlineview byitem.. what is "item" ?
Re: Outlineview byitem.. what is "item" ?
- Subject: Re: Outlineview byitem.. what is "item" ?
- From: Matt Neuburg <email@hidden>
- Date: Mon, 9 Sep 2002 08:11:26 -0700
On Sun, 8 Sep 2002 20:40:35 +0100, Keith Pritchard <email@hidden> said:
>
I have an outlineview with controller that needs to respond to
>
- (id)outlineView:(NSOutlineView *)outlineView
>
objectValueForTableColumn:(NSTableColumn *)col byItem:(id)item
This is not a "controller" method; it's a data source method. It can be
important to keep these things distinct.
>
My problem is, what is "item" ?
It's whatever you handed Cocoa when it asked you for the item originally,
in outlineView:child:ofItem:. It's a simple case of "whatever goes around,
comes around" (also known as "garbage in, garbage out").
Look at the four required methods in NSOutlineViewDataSource. I call these
the Four Big Questions. Think about these questions - not one at a time,
but all at once, and as consequences of one another. If you can't answer
all of them, you've designed your data model wrong. So, clearly, you should
design your data model so that you *can* answer all of them.
So, what's the first question? It's outlineView:numberOfChildrenOfItem:,
because if your answer to this question is 0, you won't be asked any more
questions. Can you determine quickly how many children any item has? Not
just top level items (where the parameter here will be nil), but any of
your own items as well? That is, does every one of your items, at every
depth of your data structure, carry somehow within itself the answer to
this question?
Once you are satisfied, then go on to the next question,
outlineView:isItemExpandable:. Then on to outlineView:child:ofItem:. And
finally outlineView:objectValueForTableColumn:byItem:.
Your entire job as data source is to have a data structure such that you
can continue to answer questions as the catechism sequence unfolders. The
objectValue question is the last in the sequence (conceptually at least),
so think of it as the payoff. You must see to it that your items carry with
them the information you need in order to answer the objectValue question
with regard to them. In short, if you don't know the answer, instantly,
when you are handed an item, then you've been answering the other questions
wrong. m.
--
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
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.