I'm using NSOutlineView for a project, and can't seem to figure out two things:
- How to remove the disclosure triangle for tree nodes. Apps like iTunes seem to be able to do this:
Is there some sort of NSOutlineView Delegate method that is used for this? Or does it require a subclass?
- How to disable indenting for items. I've tried using setIndentationPerLevel: and setting it to 0, as well as changing the column indent to 0 in Interface Builder, but it does not seem to have any effect.
You've run into the right person here. I've had to grapple with this just a week ago.
Removing the disclosure triangle: implement the
frameOfOutlineCellAtRow:
method in yourNSOutlineView
subclass and returnNSZeroRect
(only if you want to hide that particular row's triangle, of course.)Disable indenting: the outline view's standard layout reserves space at the far left to draw the triangles in, in case the item is expandable. But you can override that for individual items by specifying a different drawing frame. You also do that in your subclass, by responding to this message:
For future reference, the cleanest and simplest way to hide the disclosure triangle in expandable NSOutlineView items is by implementing the outlineView:shouldShowOutlineCellForItem: method of the NSOutlineViewDelegate protocol in your delegate:
The correct way to specify the intention per level is by overwriting
indentationPerLevel
of NSOutlineView.This will make sure children have the same indention as the parents.
I had to combine the two approaches above because
outlineView:shouldShowOutlineCellForItem:
alone does not remove the space reserved for the disclosure triangles (it does remove the triangles themselves).Delegate:
Subclass of NSOutlineView:
Result:
I tried this in Swift. It just works. I don't know whether it is a proper way. There should be equivalent in Obj-C:
Be sure you return YourHeaderCellClass item in datasource method.
Use PXSourceList. It's the style you're looking for with a very nice api.