0

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

这是我需要的四种方法:

//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;
}
4

1 回答 1

1
于 2013-03-24T03:39:07.900 回答