Affichage en arbre

mulot

Membre confirmé
12 Février 2003
19
0
Bonjour,

Quelle classe NS dois je utiliser pour avoir un affichage en arbre comme on peut le trouver en mode list dans le finder ?
J'ai essayé un NSBrowser mais j'ai un affichage en colonne de mon arbre.

Quelqu'un a une idée et si possible un exemple de code ?

Merci.
 
exemple local

file:///Developer/Examples/AppKit/OutlineView/

ou

http://monkeyfacepresident.online.fr/b/RowResizableViews.dmg.bz2

:zen: :zen: :zen:

tiens cocoadev mailing-list

Re: OutlineView data source method

FROM: Andy Lee
DATE: 2002-03-10 00:11

At 11:01 PM -0500 3/8/02, Adam Atlas wrote:
>- (id)outlineView: (NSOutlineView * )outlineView objectValueForTableColumn: (NSTableColumn * )tableColumn byItem: (id)item;
>
>What, exactly, is passed to this method, and what should be returned?

The short answer is: "item" is an object containing the data for one row of the outline view. *The above method returns one value from that row.

In case you need more detail, here's a more long-winded answer in Q&A form:

Q: How do outline views display their data?

A: You create a "datasource" object that implements NSOutlineViewDataSource methods. *You attach the datasource to the outline view. *When the outline view needs to display itself, it will ask the datasource for values to display, using the methods you implemented. *Note that you never call these methods yourself. *The outline view will call them at the appropriate times.

Q: What is the "item" referred to in all those NSOutlineViewDataSource methods?

A: An "item" is an object that contains the data values for one row of your outline. * This is the thing to understand as you implement all the datasource methods. *For example, you must implement -outlineView: child: ofItem: so that the following:

** *[myDataSource outlineView:myOutlineView child:4 ofItem:anItem]

returns the 5th child of anItem (not the 4th, because items are zero-indexed). *"anItem" can be nil, in which case the above expression returns the top-level item in the outline.

It's up to you as the implementer of the datasource to decide what class of object is used for the "items." *NSOutlineView doesn't care what you use as long as your datasource answers all the right questions.

Q: What does -outlineView: objectValueForTableColumn:byItem: return?

A: Just as each row of the outline is represented by an object, so is each value within the row. *That value is the "data object" returned by the method you asked about. *Exactly what it returns depends on the type of data it is. *See the docs for NSTableView (which is the superclass of NSOutlineView) for details on how to match data objects to displayed values.

Q: Speaking of the docs, how might I have figured out NSOutlineView despite the sketchy documentation?

A: By far the best tip I can offer is to put the Cocoa docs into a search tool like MTLibrarian, MarshmallowLibrarian, or Sherlock. *(I personally don't like Sherlock, but suit yourself.) *Knowing how to get around the docs is one of THE most important skills in Cocoa programming.

I don't recommend indexing the whole /Developer/Documentation directory. *Instead, create separate indexes for (at least) these directories:

/Developer/Documentation/Cocoa/Reference/ProgrammingTopics
/Developer/Documentation/Cocoa/Reference/TasksAndConcepts
/Developer/Documentation/Cocoa/Reference/ApplicationKit
/Developer/Documentation/Cocoa/Reference/Foundation
/Developer/Examples/AppKit

Let's take -outlineView: objectValueForTableColumn:byItem:, which you asked about before. * The convenient thing about this method*is that it has a pretty unique-looking name. * If you use MTLibrarian to search for "objectValueForTableColumn", anything you find is probably going to be useful. *Besides the obvious ApplicationKit directory, one good place to look is in the AppKit examples, which contain two examples of this particular method being used.

One more tip. * To understand a class, it often helps to understand its superclass. *The Cocoa docs make this really easy. *For each class, there is a link at the top of the page to the doc for its superclass.

Hope this helps,
--Andy