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.
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.
来源:https://stackoverflow.com/questions/15492767/shaving-a-couple-levels-of-indentation-off-of-an-nsoutlineview