NSOutlineView:删除显示三角形和缩进 [英] NSOutlineView: remove disclosure triangle and indent

查看:244
本文介绍了NSOutlineView:删除显示三角形和缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NSOutlineView进行项目,但似乎无法弄清楚两件事:

I'm using NSOutlineView for a project, and can't seem to figure out two things:

  • 如何删除树节点的显示三角形. iTunes之类的应用似乎可以做到这一点:

是否存在用于此目的的某种NSOutlineView Delegate方法?还是需要一个子类?

Is there some sort of NSOutlineView Delegate method that is used for this? Or does it require a subclass?

  • 如何禁用项目缩进.我尝试使用 setIndentationPerLevel:并将其设置为0,以及在Interface Builder中将列缩进更改为0,但似乎没有任何效果.
  • How to disable indenting for items. I've tried using setIndentationPerLevel: and setting it to 0, as well as changing the column indent to 0 in Interface Builder, but it does not seem to have any effect.

推荐答案

您在这里遇到了合适的人.就在一周前,我不得不解决这个问题.

You've run into the right person here. I've had to grapple with this just a week ago.

删除显示三角形:在您的NSOutlineView子类中实现frameOfOutlineCellAtRow:方法并返回NSZeroRect(当然,仅当您要隐藏该特定行的三角形时).

Removing the disclosure triangle: implement the frameOfOutlineCellAtRow: method in your NSOutlineView subclass and return NSZeroRect (only if you want to hide that particular row's triangle, of course.)

- (NSRect)frameOfOutlineCellAtRow:(NSInteger)row {
    return NSZeroRect;
}

禁用缩进:如果项目是可扩展的,则大纲视图的标准布局在最左侧保留用于绘制三角形的空间.但是,您可以通过指定其他图纸框来覆盖单个项目的内容.您还可以通过响应以下消息在子类中执行此操作:

Disable indenting: the outline view's standard layout reserves space at the far left to draw the triangles in, in case the item is expandable. But you can override that for individual items by specifying a different drawing frame. You also do that in your subclass, by responding to this message:

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


    if ((column == 0) /* && isGroupRow */) {
        return NSMakeRect(0, superFrame.origin.y, [self bounds].size.width, superFrame.size.height);
    }
    return superFrame;
}

这篇关于NSOutlineView:删除显示三角形和缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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