small medium large xlarge

Back to: All Forums  Core Data
Generic-user-small
03 Mar 2009, 04:27
Sean Rich (5 posts)

I have a core data model with an entity that has a tree structure (parent, children relationships). I’d like to represent this in a table view so that only a portion of the tree is displayed. Double clicking on an item would bring up only the children of that item, double click one of those items to get its children and so on. (Transmit is a good example of this kind of behavior using file system objects.) I considered using a tree controller in entity mode that feeds an array controller with its selection key, but you can’t select a ‘root’ that points to the array of top-level objects (in this model there will be several root objects). I’m at a loss on how to display only part of a tree using core data - even with Marcus’ excellent book.

Note: I realize that this could be done easily with an outline view, but due to design considerations the table view method is necessary.

-Sean

Avatarsmall_pragsmall
12 Mar 2009, 00:22
Marcus S. Zarra (284 posts)

That is an interesting problem. Personally I would use a table view as you have stated and capture its double click event. I would then switch the table view’s data to the next level and have the table reload. While you can do this with a NSArrayController and switch its content around, you might gain more control by using the NSTableDataSource protocol instead.

Another consideration is to do something like LighthouseKeeper has done with its source list. When an element is clicked on (in your case double clicked), the existing table view slides out to the left using Core Animation and an entirely new table view slides in from the right. This presents the user with a solid UI experience. It also lets you have a single table view per level of data.

Generic-user-small
13 Mar 2009, 02:58
Sean Rich (5 posts)

Thanks for the reply, Marcus. I agree that using a data source for the table would be flexible, but it would mean maintaining my own tree in memory. My solution to the problem has been to use a default root node with its children bound to the content of an NSArrayController (similar to what you suggested). Selecting a child updates the pointer bound to the array controller. It greatly simplifies the code by having the array controller do most of the work for me.

I took a look at LighthouseKeeper and we’re thinking on similar lines. I originally tried to use an NSBrowser with a single column, but it was a pain to deal with so I’m using a table view and core animation to simulate the same effect of sweeping one table to the next as in the iPhone. Thanks again for your help!

You must be logged in to comment