首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态NSOutlineView数据源

动态NSOutlineView数据源
EN

Stack Overflow用户
提问于 2013-06-01 03:00:07
回答 1查看 637关注 0票数 5

因此,我实现了一个与苹果的NSOutlineView数据源示例非常相似的PXSourceList数据源。

事情是这样的.

代码语言:javascript
复制
- (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item; {
    if (item == nil) {
        // item is nil so it's part of the very top hierarchy.
        // return how many sections we need.
        return 2;
    }
    else {
        if ([item class] == [TSFileSystemItem class] ) {
            return [item numberOfChildren];
            // if item isn't nil and it's a TSFileSystemItem, then return it's children.
        }
        if ([item class] == [TSWorkspaceItem class]) {
            return 2; // i don't know, random items.
        }
        else {
            NSLog(@"this is a special object.");
        }
    }
}

- (BOOL)sourceList:(PXSourceList *)aSourceList isItemExpandable:(id)item {
    if (item == nil) {
        return YES;
    }
    else {
        // if the number of children of the item is -1
        BOOL gibberhook = ([item numberOfChildren] != -1);
        return gibberhook;
    }
}

-(id)sourceList:(PXSourceList *)aSourceList child:(NSUInteger)index ofItem:(id)item {
    if (item == nil) {
        return [TSFileSystemItem rootItem];
    }
    else {
        return [(TSFileSystemItem *)item childAtIndex:index];
    }
}

- (id)sourceList:(PXSourceList *)aSourceList objectValueForItem:(id)item {
    if (item == nil) {
        return @"/";
    } else {
        if (item == [TSFileSystemItem rootItem]) {
            return PROJECT_FILES;
        }
        else {
            return [item relativePath];
        }
    }
}

神秘的TSFileSystemItem来自这里:https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/OutlineView/Articles/UsingOutlineDataSource.html

所有这些都是可以的,除了我想将我的源列表划分为多个部分(根单元)。一个显示文件层次结构(检查),另一个...

好的,另一个将包含一个NSMutableArray,我从其他部分向其中添加条目。听起来很复杂?更好的解释。单击具有文件层次结构的节中的项目,它将被添加到其他节中。

我试图在苹果文档的帮助下解决这个问题,但我仍然找不到一种简单、高效、稳定的方法来制作具有上述功能的两个部分。如果它像为UITableView配置数据源一样简单……

有谁能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2013-08-04 07:00:48

当调用childrenForItem委托方法并且项在nil中时,这将请求树的根。如果返回and数组,则该树将为该数组中的每个元素创建一个根节点。

代码语言:javascript
复制
- (NSArray *)childrenForItem:(id)item {
    if (item == nil) {
        return [self.rootTreeNode childNodes];
    } else {
        return [item childNodes];
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16864082

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档