Objective c 动态NSOutlineView数据源
因此,我实现了一个Objective c 动态NSOutlineView数据源,objective-c,cocoa,datasource,nsoutlineview,pxsourcelist,Objective C,Cocoa,Datasource,Nsoutlineview,Pxsourcelist,因此,我实现了一个PXSourceList数据源,该数据源与苹果公司的NSOutlineView数据源的示例非常相似 事情就是这样的 - (NSUInteger)sourceList:(PXSourceList*)sourceList numberOfChildrenOfItem:(id)item; { if (item == nil) { // item is nil so it's part of the very top hierarchy. //
PXSourceList
数据源,该数据源与苹果公司的NSOutlineView
数据源的示例非常相似
事情就是这样的
- (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];
}
}
}
神秘的tsfilesystemem
来自这里:
所有这些都是可以的,只是我想把我的源列表分成多个部分(根单元格)。一个显示文件层次结构(检查),另一个
另一个将包含一个NSMutableArray
,我将从另一个部分向其中添加项。听起来很复杂?更好的解释。单击具有文件层次结构的节中的某个项目,该项目将添加到另一个节中
我曾试图借助苹果的文档来解决这一问题,但我仍然找不到一种简单、高效、稳定的方法来制作具有上述功能的两个部分。如果能像为UITableView
配置数据源一样简单就好了
有人能帮我一下吗?当调用childrenForItem委托方法且item为nil时,这会请求树的根。如果返回并数组,则树将为该数组中的每个元素都有一个根节点
- (NSArray *)childrenForItem:(id)item {
if (item == nil) {
return [self.rootTreeNode childNodes];
} else {
return [item childNodes];
}
}
您是否注意到
NSOutlineView
中的-(BOOL)outlineView:(NSOutlineView*)outlineView isGroupItem:(id)item
?我会调查一下的,谢谢。