6

I have an outline view where I don't want to indent the top couple levels (they have a distinctive appearance anyway), but I do want to indent subsequent levels. How can I do this?

I've tried overriding -levelForRow: and -levelForItem: to subtract 2 from the return values, but this didn't help. I also tried overriding -frameOfOutlineCellAtRow: to subtract 2 * indentationPerLevel from the frame's width, but that didn't help either, possibly because I'm not showing disclosure triangles. Any thoughts about how I can fix this issue?

The outline view is bound to an NSTreeController, which makes it difficult to flatten the underlying data structure, but I do have an outline view delegate set up.

Becca Royal-Gordon
  • 17,541
  • 7
  • 56
  • 91
  • Can you show me an screen shot or sketch what you want. Anyways check my answer and screen shot, and comment if this is what you want? – Anoop Vaidya Mar 20 '13 at 07:22

1 Answers1

9

The solution is to use frameOfCellAtColumn:row: which is an NSTableView method.

- (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row;
{
    NSRect frame = [super frameOfCellAtColumn:column row:row];

    if (column == (NSInteger)[self.tableColumns indexOfObjectIdenticalTo:self.outlineTableColumn]) {
        if (this-item-or-row-matches-your-conditions) {
            frame.origin.x -= self.indentationPerLevel;
            frame.size.width += self.indentationPerLevel;
        }
    }

    return frame;
}

This method controls the layout in both cell-based and view-based table views and outline views.

seth
  • 1,647
  • 1
  • 12
  • 20