NSOutlineView缩进问题 [英] NSOutlineView indentation issue

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

问题描述

我使用一个NSOutlineView对象来表示一个文件结构,并发现它不会正确缩进任何可扩展的孩子,尽管它会缩进不是的孩子。

I'm using an NSOutlineView object to represent a file structure and am finding that it will not correctly indent any children which are expandable, though it will indent children that aren't.

这里是一张照片来显示我的意思:

Here's a picture to show what I mean:

在此示例中,AnotherFolder是Folder2的子项,但它不缩进与其他缩进文件。奇怪的是,AnotherFolder的孩子AnotherFile.java确实缩进(2级)。

In this example, "AnotherFolder" is a child of "Folder2" yet it does not indent in line with the other indented files. Curiously enough, the child "AnotherFile.java" of "AnotherFolder" does indent correctly (2 levels in).

我已经尝试将属性设置为indentationFollowsCells可用。这似乎应该很简单,但我不能解决它。

I have tried setting properties such as "indentationFollowsCells" to no avail. This seems as though it should be very simple but I can't solve it.

谢谢!

strong>编辑:根据请求提供一些额外信息:

Some extra information upon request:

我使用NSOutlineViewDataSource协议来实现,下面是与之相关的代码:

I am using the NSOutlineViewDataSource protocol for the implementation, here is the code related to that:

- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
    return item;
}

- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
    NSMutableDictionary* dict;
    if(item == nil) {
        dict = fileTree;
    } else {
        dict = [((MyFile*) item) children];
    }

    NSArray* keys = [dict allKeys];
    NSArray* sorted = [keys sortedArrayUsingSelector:@selector(compare:)];
    NSString* key = [sorted objectAtIndex:index];
    return [dict objectForKey:key];
}

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
    return [[item children] count] > 0;
}

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
    if(item == nil) {
        return [fileTree count];
    }
    return [[item children] count];
}


推荐答案

大纲视图。

Try changing your outline view from a Source outline view to a normal one.

这篇关于NSOutlineView缩进问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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