文本不显示在“SourceList”大纲视图中

时间:2013-09-28 01:59:40

标签: objective-c macos cocoa nsoutlineview nstablecellview

我使用的是“SourceList”OutlineView,无法获取要显示的“标题”和“数据”NSTableCellViews的内容。 OutlineView的结构正常运行,我的应用程序运行,看起来与此类似http://i.stack.imgur.com/0E4D8.png

这是我的代码:

- (id)init {
            self = [super init];
            if (self) {
                _masterFolder = [[NSMutableArray alloc] init];
                MasterFolder *trueMaster = [[MasterFolder alloc] initMaster:@"Categories"];

                [_masterFolder addObject:trueMaster];
                [trueMaster addChild:[[MasterFolder alloc] initMaster:@"World"]];
                [trueMaster addChild:[[MasterFolder alloc] initMaster:@"Sports"]];
                [trueMaster addChild:[[MasterFolder alloc] initMaster:@"Local"]];
                [trueMaster addChild:[[MasterFolder alloc] initMaster:@"Business"]];

                [(MasterFolder *)[trueMaster.children objectAtIndex:0] addChild:[[MasterFolder alloc] initMaster:@"Middle East"]];
            }
            return self;
    }


    - (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
        return !item ? [self.masterFolder count] : [[item children] count];
    }

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

    - (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
        return !item ? [self.masterFolder objectAtIndex:index] : [[item children] objectAtIndex:index];
    }
    - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item {
        if (![item isKindOfClass:[MasterFolder class]]) {
            return [outlineView makeViewWithIdentifier:@"HeaderCell" owner:self];
        } else {
            NSTableCellView *cellView = [outlineView makeViewWithIdentifier:@"DataCell" owner:self];
            cellView.textField.stringValue = [((MasterFolder *)item) name];
            return cellView;
        }
    }

我知道这个功能有问题:

    - (NSView *)outlineView:(NSOutlineView *)outlineView viewForTableColumn:(NSTableColumn *)tableColumn item:(id)item { 

但我不知道要改变什么才能让它发挥作用。我已经在Stack Overflow上看了很多类似的帖子,并且无法获得提供的解决方案。

0 个答案:

没有答案