隐藏源列表中的显示/隐藏按钮(基于视图的大纲视图)

时间:2013-05-16 04:41:38

标签: macos cocoa nsoutlineview

enter image description here

如何隐藏显示/隐藏按钮(编辑为此处展开)。即使我将其设置为空字符串,数据单元格的边框也会缩小,如图所示。以前我使用方法- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item,它隐藏显示/隐藏字符串并完美地工作。但问题是outlineview只允许展开而不是折叠。我想通过单击相应的父节点一次只展开一个父节点。

2 个答案:

答案 0 :(得分:10)

使用NSOutlineViewDelegate方法中的此方法:

  • (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item;

答案 1 :(得分:1)

终于解决了它,this code帮助了我。

- (NSRect)frameOfOutlineCellAtRow:(NSInteger)rowIndex
{
    NSRect superFrame = [super frameOfOutlineCellAtRow:rowIndex];

    // Return NSZeroRect if the row is a group row
    if ([[self delegate] respondsToSelector:@selector(outlineView:isGroupItem:)]) {
        if ([[self delegate] outlineView:self isGroupItem:[self itemAtRow:rowIndex]]) {
            return NSZeroRect;
        }
    }


    return superFrame;
}
相关问题