因此,我实现了一个与苹果的NSOutlineView数据源示例非常相似的PXSourceList数据源。
事情是这样的.
- (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配置数据源一样简单……
有谁能帮帮我吗?
发布于 2013-08-04 07:00:48
当调用childrenForItem委托方法并且项在nil中时,这将请求树的根。如果返回and数组,则该树将为该数组中的每个元素创建一个根节点。
- (NSArray *)childrenForItem:(id)item {
if (item == nil) {
return [self.rootTreeNode childNodes];
} else {
return [item childNodes];
}
}https://stackoverflow.com/questions/16864082
复制相似问题