NSOutlineView indentation issue

依然范特西╮ 提交于 2019-12-08 21:02:10

问题


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:

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

回答1:


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



来源:https://stackoverflow.com/questions/6979212/nsoutlineview-indentation-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!