我从这个链接中提到了 NSOutlineview 。我根据所选值动态加载所有值。在这里,我在获取路径时构造了一个问题。
比如,文件夹路径。(例如:D:/NewFolder/Test/blah/blah1
同样,我需要从父级获取完整路径选择的子级。在图像中,我选择了项目。所以我需要的路径应该如下所示,
/Test/New Folder/Untitled/Project
我的代码是
- (IBAction) ButtonClick:(id)sender
{
self.treeoutlineview.delegate = self;
self.treeoutlineview.dataSource = self;
NSString *roots = @"/";
NSIndexPath *indexPath = nil;
indexPath = [NSIndexPath indexPathWithIndex:[contents count]];
TreeNode *node = [[TreeNode alloc] init];
[node TitleSet:roots];
[self.treeController insertObject:node atArrangedObjectIndexPath:indexPath];
}
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
childItem = item;
return childItem;
}
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
noofchildren = 0;
return noofchildren;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
return YES;
}
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item {
valueforcolumn = nil;
}
- (BOOL)outlineView:(NSOutlineView *)ov shouldSelectItem:(id)item {
{
rec = @"New Folder|Test|Backup|Project";
NSArray *arr = [rec componentsSeparatedByString:@"|"];
[loadChildValues removeAllObjects];
NSIndexPath *indexPath = nil;
if (![self.treeController selectionIndexPath])
{
indexPath = [NSIndexPath indexPathWithIndex:[contents count]];
}
else
{
if ([[[self.treeController selectedObjects] objectAtIndex:0] isLeaf])
{
NSBeep();
return;
}
indexPath = [self.treeController selectionIndexPath];
indexPath = [indexPath indexPathByAddingIndex:[[[[self.treeController selectedObjects] objectAtIndex:0] children] count]];
}
for (int i = 2; i< [arr count]; i++) {
[loadChildValues addObject:[arr objectAtIndex:i]];
TreeNode *node = [[TreeNode alloc] init];
[node TitleSet:[arr objectAtIndex:i]];
[self.treeController insertObject:node atArrangedObjectIndexPath:indexPath];
}
}
我如何做到这一点。任何机构请帮助解决这个问题。提前致谢。