Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Outline view example?

Outline view example?
Thread Tools
Synotic
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jun 6, 2002, 12:48 AM
 
Yes, I know I asked about a table view just a couple days ago, but the way our data is structured (well needs to be, I have to restructure it...) requires parent and child items.

Lots of stuff will require rewriting.. but I am hoping I won't have too much trouble... I trust that an outline view also uses a data source, and can use an array as its data source? For more info read the "Table view example?" thread.

I guess I'll have to reask a lot of stuff now <img border="0" alt="[Hmmm]" title="" src="graemlins/hmmm.gif" /> Again, thanks for any of you that continue to put up with me <img border="0" title="" alt="[Wink]" src="wink.gif" />

P.S. I'll post an example of my data soon.
     
lindberg
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Jun 6, 2002, 01:59 AM
 
/Developer/Examples/AppKit/OutlineView
/Developer/Examples/AppKit/DragNDropOutlineView

NSOutlineView is a subclass of NSTableView, so the basic concepts are quite similar.
     
Synotic  (op)
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jun 6, 2002, 11:27 PM
 
I looked at those, it looked pretty confusing, I asked a couple people more experienced than me and either they've never used an outline view or they couldn't make since of the example either...

However I am told by someone who uses a bunch of custom classes for an outline view that it's not possible to have an array/dictionary be its data source.. is this true? I am going to be thousands of items so it needs to be fairly speedy. Well Cocoa be able to do this without too much of a lag? I tried to do a description on the data source but it wasn't anything I could use...
     
Synotic  (op)
Mac Elite
Join Date: Oct 2000
Status: Offline
Reply With Quote
Jun 6, 2002, 11:28 PM
 
OK, so you can't delete posts.. pfft..

<small>[ 06-06-2002, 11:39 PM: Message edited by: Synotic ]</small>
     
lindberg
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status: Offline
Reply With Quote
Jun 7, 2002, 12:01 AM
 
If you have a consistently constructed NSDictionary, then maybe, but it's probably not worth it. If you already have your data in a parent/children structure, it should be fairly easy.

In this example, a TreeNode object has an NSArray of children, with each object in that array being another TreeNode. TreeNode has a couple of convenience mehods -childAtIndex: and -numberOfChildren,
which are just covers for NSArray's -objectAtIndex: and -count methods.

The main thing to realize is that NSOutlineView passes back the parent "item" it needs information for. If the item is nil, then it's looking for info on the top-level node.

</font><blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">/******************************************
** Outline View DATA SOURCE METHODS
*******************************************/
// This method just returns back the appropriate TreeNode
// object for an &quot;item&quot; dataSource parameter. If the item
// is nil, then we return the root node (controllerTree),
// which is an ivar of this controller class. Otherwise,
// just use the item itself, which is a TreeNode object.
// I believe the examples in /Developer/Examples/AppKit/OutlineView
// do this with a macro, which is a little bit faster but
// may be more confusing when you're trying to learn this stuff.
- (TreeNode *)_nodeForItemid)outlineItem
{
return outlineItem == nil? controllerTree : (BFTreeNode *)outlineItem;
}

// return the specified child of a node. When the outline
// view wants children of that child, then the object returned
// here will be the &quot;item&quot; in a future call of this method.
- (id)outlineViewNSOutlineView *)outlineView childint)anIndex ofItemid)item
{
return [[self _nodeForItem:item] childAtIndex:anIndex];
}

- (BOOL)outlineViewNSOutlineView *)outlineView isItemExpandableid)item
{
return ([[self _nodeForItem:item] numberOfChildren] &gt; 0);
}

- (int)outlineViewNSOutlineView *)outlineView numberOfChildrenOfItemid)item
{
return [[self _nodeForItem:item] numberOfChildren];
}</pre><hr /></blockquote><font size="1" face="Geneva, Verdana, Arial, sans-serif">Now, if you have things structured as NSDictionary objects that always
have a "children" key, which points to an NSArray of more of these
NSDictionary objects, then the "items" are the NSDictionary objects,
and you do things like [[item objectForKey:@"children"] count] and
[[item objectForKey:@"children"] objectAtIndex:theIndex].

Just remember if the "item" parameter is nil,
then you want to return the top-level information.
     
macrophyllum
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Feb 23, 2003, 02:47 AM
 
So how do you set up the data source to display everything except for the highlest level root item?

For example, in Interface Builder when working with an outline view it displays something like:

Size {large, medium, small}
Color {red, orange, blue}
Weight {light, medium, heavy}

But none of these items are "nested" in the highest level root item? I have noticed a few other apps do this. How is it done? I have looked at the sample code, but I can't figure it out from that.
     
Uncle Skeleton
Addicted to MacNN
Join Date: Nov 2002
Location: Rockville, MD
Status: Offline
Reply With Quote
Feb 27, 2003, 03:39 PM
 
yeah, I'd like to know that too. I'd just given up on finding that because it's superficial, but it would be really cool to know
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 09:34 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,