从NSOutlineView中削减几个级别的缩进 [英] Shaving a couple levels of indentation off of an NSOutlineView

查看:489
本文介绍了从NSOutlineView中削减几个级别的缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大纲视图,其中我不想缩进顶部几个水​​平(他们有一个独特的外观反正),但我做想缩进后续水平。

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?

我尝试覆盖 -levelForRow: levelForItem:从返回值中减去2,但这没有帮助。我也尝试重写 -frameOfOutlineCellAtRow:从框架的宽度减去2 * indentationPerLevel,但是没有帮助,可能是因为我不显示公开三角形。关于我如何解决这个问题的任何想法?

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?

大纲视图绑定到 NSTreeController 难以平整底层数据结构,但我确实有一个大纲视图委托设置。

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.

推荐答案

解决方案是使用 frameOfCellAtColumn:row:这是一个 NSTableView 方法。

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.

这篇关于从NSOutlineView中削减几个级别的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆