I have looked over the google but have not found many examples on this. Most only relate to the NSTableView.
How do I subclass my NSOutlineView to look exactly like XCode's plist editor? I've do not know how to get the border colors shown below. I currently have it working exactly the same, except for the coloring. Any help would be appreciated.
UPDATE The part I am confused about is what the draw code should look like. Google didnt help me much on this.
Step 1: Create an
NSTableViewRow
subclassThe borders are drawn on the
NSTableRowView
instances that make up the table's rows. To get them, you could subclassNSTableRowView
and give it aborders
property that stores a mask specifying which borders you want drawn on the row. You'd accompany this with a custom implementation ofdrawRect
, which calls super first, and then strokes on the specified borders.Step 2: Implement the delegate methods that signal when you'll need to update the borders
In the simplest case, I can think of three:
This is where you'll find the hard work. I'd start by having a go at the last one first. There will be lots of different ways of doing it, but you could get the node that's about to be selected from the
proposedSelectionIndexes
argument in conjunction with theNSOutlineView
api. Once you've got this node you can work out which rows will need a border by getting the nodes represented in the rows below this soon-to-be-selected row. If a given node is a descendant of the new selection, then it'll need a border of some sort (hint: theindexPath
property ofNSTreeNode
comes in handy here).Step 3: Make sure the outline view is using your custom row views
Implement the following delegate method so that it returns your custom row views:
Note that the second
item
argument is anNSTreeNode
object. By keeping a record (a map of some sort) of which nodes are associated with which borders, you can then set theborder
mask property of yourNSTableRowView
subclass.