2013-03-23 49 views
0

我有NSOutlineView,目前只列出根项目的子项。一切正常,除非我尝试使用拖放方式重新排列项目。当它们需要在其他项目之间拖动时,它前面的圆形线始终位于最上面一排,并且不跟随我的物品。但是,我仍然可以正确地获得索引位置,因此我仍然可以在数据源中正确重新排列它们。我不想重新排列项目,只需将它们拖放到对方,我只想重新排列根级别的项目(如Mac上的VLC播放列表)。当使用拖放重新排列时,小圆圈线卡在NSOutlineView顶部

这里是我的四个必需的方法:

//queue is a C-based data structure 

-(NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item 
{ 
    if(item == nil){ 
     return queue.count; //each list item 
    }else{ 
     return 0; //no children of each list item allowed 
    } 
} 

-(id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item 
{ 
    if(item != nil) return nil; 

    return [[NSDictionary dictionaryWithObjectsAndKeys: 
      [NSNumber numberWithLong:index],@"index", 
      [NSString stringWithFormat:@"%s",queue.item[index].filepath],@"filePath", 
      nil] copy]; 
} 

-(BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item 
{ 
    if(item == nil){ 
     return YES; 
    }else{ 
     return NO; 
    } 
} 

-(id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item 
{ 
    if(item == nil) return nil; 

    return [item objectForKey:[tableColumn identifier]]; 
} 

而且我拖方法:

-(BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard 
{ 
    [pasteboard declareTypes:[NSArray arrayWithObject:LOCAL_REORDER_PASTEBOARD_TYPE] owner:self]; 
    [pasteboard setData:[NSData data] forType:LOCAL_REORDER_PASTEBOARD_TYPE]; 
    return YES; 
} 

-(NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index 
{ 
    NSUInteger op = NSDragOperationNone; 

    if(index != NSOutlineViewDropOnItemIndex){ 
     op = NSDragOperationMove; 
    } 
    return op; 
} 

回答

1

我有点困惑什么期望你想要的行为。这是否样本项目达到预期的拖放突出特性(它显示每行之间的o––––––指标,它是VLC如何出现在这里工作对我来说):

http://www.markdouma.com/developer/NSOutlineViewFinagler.zip

(请注意,它不包括代码还没有实际进行项目的重新排序)。

如果不是,你可以再次描述它现在做什么以及你想要做什么?

此外,您并未在此处包含代码,但您是否确保注册LOCAL_REORDER_PASTEBOARD_TYPE拖动类型的大纲视图?我会做在awakeFromNib

- (void)awakeFromNib { 
    [self.outlineView registerForDraggedTypes:@[LOCAL_REORDER_PASTEBOARD_TYPE]]; 
} 

这是必要的大纲视图允许自己受到拖累目的地。