-1

我正在实施 NSOutlineView 并实施了以下方法,

    -(void) initOutlineView{

        pMyOutlineView       = [[[MyUICustomOutlineView alloc] initWithFrame:clipViewBounds]          
                                autorelease];

    NSTableColumn*  firstColumn     = [[[NSTableColumn alloc] initWithIdentifier:@"firstColumn"] autorelease];
    [firstColumn setWidth:25];
    [pMyOutlineView  addTableColumn:firstColumn];

    NSTableColumn*  secondColumn        = [[[NSTableColumn alloc] initWithIdentifier:@"secondColumn"] autorelease];
        NSTextFieldCell *pCell = [[NSTextFieldCell alloc]init];

        [secondColumn setDataCell:pCell];
        [secondColumn setWidth:180];

        [pMyOutlineView  addTableColumn:secondColumn];
        [pMyOutlineView setRowHeight:30];


        pNodeArray = [[NSMutableArray alloc]initWithCapacity:10];

        PointerNode *pNode = pointerList.getHead();

        int idx =0;
        void *ptr = nil;
        while ( contact ) {
            [pNodeArray insertObject:[NSValue valueWithPointer:(void *)pNode] 
                atIndex:idx];
            pNode = pNode->getNext();
            idx++;

        }

        [pMyOutlineView setDataSource:self];
        // this is to tell myCustomOutlineView to delegate Menu and Mouse event to 
        // this interface
        [pMyOutlineView setDataDelegate:self];
        [scrollView setDocumentView:pMyOutlineView];

        [pMyOutlineView setDelegate:self];


}

并实现了以下委托方法

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {

        // Here it will come for the top level element 
    if(item==nil) 
        return pointerList.size();

    /* 
     If its not NULL then it must be some child element 
     */
    if([item isKindOfClass:[NSValue class]])
    {
                // yes it may have children 
        PointerNode *pNode = (PointerNode *)[item pointerValue];
        if(pNode->hasChildren()){
            return pNode->getNoOfChild();
        } 
    }
    return 0; // means this element not going to have any children 
}

其他一些方法

- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item

并获取数据

我正在关注一些博客、教程,我面临的问题是作为标准文档,它应该在 numberOfChildrenOfItem 中针对我们需要计算并发送该项目的子项编号的每个元素命中,但我面临的问题是仅使用一次上述功能,并且该项目也为零,即它不适用于其他元素,我是否缺少任何需要委托的方法

我覆盖的其他方法如下,

- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item

- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)aTableColumn byItem:(id)item

- (void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item

- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item

请告诉我,我缺少哪种方法

4

2 回答 2

3

outlineView:numberOfChildrenOfItem:中,您需要测试 item 是否是nil,如果是,则返回顶级对象的子对象数。引用文档

如果itemnil,则此方法应返回顶级项目的子项数。

如果您0在 item is 时返回nil,则大纲视图认为顶级项目没有子项,因此它不会再次将此消息发送到您的数据源对象。

于 2011-01-29T09:13:15.450 回答
0

@Rohan您是否实现了数据源方法。

查看 NSOutlineView 的文档

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSOutlineView_Class/Reference/Reference.html

于 2011-01-29T09:04:01.720 回答