2014-07-15 6 views
1

enter image description here어떻게이 <a href="https://github.com/JanX2/CoolOutliner" rel="nofollow noreferrer">link</a>에서 NSOutlineview을 언급 한

NSOutlineView + NSTreeController에서 선택된 노드의 전체 경로를 얻을 수 있습니다. 선택한 값을 기반으로 모든 값을 동적으로로드합니다. 여기에 경로를 얻는 동안 문제가 구조체.

마찬가지로 폴더 경로. (예 : 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]; 
} 

} 

내가이 작업을 수행하는 방법. 모든 신체 PLS 도움이 사전에이. 감사를 해결하는 것입니다.

+0

당신은 어떤 당신이 시도 코드와 어떤 부분을 이해 할 필요를 게시 할 수 ? 귀하의 질문이 너무 광범위합니다. – uchuugaka

+0

@uchuugaka 코드를 업데이트했습니다. Pls 내 코드를 확인하십시오. – akk

답변

1

내가 그것을했다. 나는 FOLL는 않았어 빚진 코드. 필요하다면이 코드를 사용하십시오. 첫 번째 단계에서

유는 항목의 Indexpath를 얻을 필요가

- (IBAction)RefreshTree:(id)sender { 
    NSIndexPath *indexPath = nil; 
    if (![self.treeController selectionIndexPath]) { 
     indexPath = [NSIndexPath indexPathWithIndex:[contents count]]; 
    } 
    else { 
     if ([[[self.treeController selectedObjects] objectAtIndex:0] isLeaf]) { 
      NSBeep(); 
      NSIndexPath *selectedfiler_indexPath = [[[self.treeController selectedNodes] objectAtIndex:0] indexPath]; 
      [self selectValue:selectedfiler_indexPath]; 
     } 
     else 
     { 
      indexPath = [self.treeController selectionIndexPath]; 
      [self selectValue:indexPath]; 
     } 
    } 
} 

- (void) selectValue : (NSIndexPath *) indexpath 
{ 
    NSMutableArray *dummyval = [[NSMutableArray alloc] init]; 
    NSTreeNode *firstSelectedNode = [[self.treeController selectedNodes] objectAtIndex:0]; 
    NSString *getsel = [firstSelectedNode representedObject]; 
    [dummyval addObject:getsel]; 
    int i = 0; 
    NSInteger j = [[firstSelectedNode indexPath]length]; 
    while (i < j) { 
     firstSelectedNode = [firstSelectedNode parentNode]; 
     if (i < j -1) 
     { 
      NSString *st = [firstSelectedNode representedObject]; 
      [dummyval addObject:[NSString stringWithFormat:@"%@",st]]; 
     } 
     i++; 
    } 

    NSArray *reversedArray = [[dummyval reverseObjectEnumerator] allObjects]; 
    NSString *ret_path=[reversedArray componentsJoinedByString:@"/"]; 
    ret_path = [ret_path substringWithRange:NSMakeRange(1, [ret_path length] - 1)]; 
    NSLog("%@",ret_path); 
} 

출력입니다 : 테스트/새 폴더/제목/프로젝트

+0

감사합니다! – ctietze

+0

@ctietze가 내 코드가 맞습니까? 아니면 나중에 문제가 발생합니까? – akk

+0

노드/트리 순회가 잘 작동하고 최신 API로 최신 상태로 유지됩니다 (가능한 한 알 수 있습니다). 나는 다른 무엇을 위해 그것을 필요로했다. 그러나 당신의 코드는 처음에'NSTreeCollection'을 가지고 어떻게 동작하는지 이해하게 만들었다. – ctietze