On Oct 14, 2011, at 09:24 , Koen van der Drift wrote:

> I’m trying to find out how to create the grayish, static items in an
> NSOutlineView, eg “Library” in iTunes or “Mailboxes” in Mail.
> Sometimes they have a disclosure triangle, eg "Devices" in the Finder.
> I think I need to subclass NSCell to change the font, etc.

Subclassing isn't necessary. This is how "group" rows appear in an outline view 
with the "source list" display style. You use delegate methods to customize the 
exact appearance: 'outlineView:isGroupItem:' indicates a group item; 
'outlineView:shouldShowOutlineCellForItem:' suppresses the disclosure triangle 
on those rows. There may be other methods you need to use to get exactly the 
horizontal and vertical spacing of the iTunes list -- I forget the details.

> But I am
> not sure how to identify these, would an attribute “isStaticItem” for
> my Group Entity or something like that be a good approach?
> 
> Secondly, are they part of the NSOutlineView, and the underlying
> NSTreeController and CoreData model?  Just like in the abovementioned
> examples, these items are already present when the app is started up
> the first time, so if they are part of the core data model, they must
> be created programmatically at first, and become part of the model
> once the user starts adding folders and items. So if the app doesn’t
> find a database, it will create the starting list.  Again, is this the
> correct approach?

One way to do this is to set up an "intermediate" data model for your list, 
since the structure of the list doesn't match the structure of your actual data 
model. When I do this, I typically define a ListItem class -- a subclass of 
NSTreeNode is easiest, since you'll likely want to follow parent/child 
relationships for various reasons -- with a "representedObject" property that 
can be set to various things -- a string, for header items, or a Core Data 
object for detail rows.

Thus you end up with a tree structure of ListItem objects, which you can then 
feed to the outline view either via your data source or via bindings.

Incidentally, since this tree structure exists only to service the outline 
view, the proper place to create it is in the outline view's window's window 
controller. It's basically glue code, so you definitely don't want to expose it 
to the rest of your app.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to