Shaving a couple levels of indentation off of an NSOutlineView

余生颓废 提交于 2019-12-07 01:50:48

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!