NSOutlineView 缩进问题

发布于 2024-11-28 13:00:56 字数 1365 浏览 0 评论 0 原文

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

这是一张图片来说明我的意思:

NSOutlineView example

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

我尝试设置“indentationFollowsCells”等属性,但无济于事。这看起来应该很简单,但我无法解决。

谢谢!

编辑:根据要求提供一些额外信息:

我使用 NSOutlineViewDataSource 协议进行实现,以下是与之相关的代码:

- (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];
}

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:

NSOutlineView example

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).

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.

Thanks!

Edit: Some extra information upon request:

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];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

抚你发端 2024-12-05 13:00:56

尝试将大纲视图从大纲视图更改为普通视图。

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

烟花易冷人易散 2024-12-05 13:00:56

我现在遇到了这个问题,发现有点奇怪,在这篇文章发布九年后,问题仍然存在。

此行为已融入源样式中:标准内容的第一行与标题单元格对齐而不是缩进,因此所有内容都会移动一个级别。

如果您使用标题单元格,您就会想要这种行为,并且一切都很好。如果您不想使用标题单元格,则不使用 SourceList 是您唯一的选择。

缩进不正确没有标题></a><br />
<a href=正确缩进带有标题单元格的 SourceView

I ran into this right now, and found it a bit strange that nine years after this post, the problem still persists.

This behaviour is baked into the Source style: the first row of the standard content is aligned with the header cell rather than indented, so everything is shifted over by one level.

If you use header cells, you want this behaviour, and everything is fine. If you don't want to use header cells, not using a SourceList is your only option.

incorrect indentation without header
correctly indented SourceView with header cell

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文